Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Alg2TB2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Harbor Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Fernando Erd
Alg2TB2
Commits
86ecf216
Commit
86ecf216
authored
9 years ago
by
Fernando Erd
Browse files
Options
Downloads
Patches
Plain Diff
Busca Binaria Implementada
parent
af2b9b42
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
Arquivos/Loteria
+0
-0
0 additions, 0 deletions
Arquivos/Loteria
Arquivos/Main.c
+7
-2
7 additions, 2 deletions
Arquivos/Main.c
Arquivos/Pesquisa.c
+33
-0
33 additions, 0 deletions
Arquivos/Pesquisa.c
Arquivos/Vetor.c
+8
-0
8 additions, 0 deletions
Arquivos/Vetor.c
with
48 additions
and
2 deletions
Arquivos/Loteria
+
0
−
0
View file @
86ecf216
No preview for this file type
This diff is collapsed.
Click to expand it.
Arquivos/Main.c
+
7
−
2
View file @
86ecf216
#include
"Estruturas.h"
void
LerDados
(
int
*
Vetor
);
void
GeraVetor
(
int
*
Vetor
);
void
ImprimeVetor
(
int
*
Vetor
);
void
SelectSort
(
int
*
Vetor
);
void
VerificaNumero
(
int
*
Vetor
,
int
*
Escolhidos
);
void
PesquisaBinaria
(
int
*
Vetor
,
int
Elem
);
int
main
()
{
int
Vetor
[
TAM
];
int
Vetor
[
TAM
]
,
Escolhidos
[
4
]
;
LerDados
(
Escolhidos
);
GeraVetor
(
Vetor
);
ImprimeVetor
(
Vetor
);
SelectSort
(
Vetor
);
ImprimeVetor
(
Vetor
);
VerificaNumero
(
Vetor
,
Escolhidos
);
}
This diff is collapsed.
Click to expand it.
Arquivos/Pesquisa.c
+
33
−
0
View file @
86ecf216
//Arquivo com os algoritmos de busca
#include
"Estruturas.h"
int
PesquisaBinaria
(
int
*
Vetor
,
int
Elem
)
{
int
meio
,
esquerda
,
direita
;
esquerda
=
0
;
direita
=
TAM
;
do
{
meio
=
(
esquerda
+
direita
)
/
2
;
if
(
Elem
>
Vetor
[
meio
])
esquerda
=
meio
+
1
;
else
direita
=
meio
-
1
;
}
while
(
Elem
!=
Vetor
[
meio
]
&&
esquerda
<=
direita
);
if
(
Elem
==
Vetor
[
meio
])
return
(
meio
);
else
return
-
1
;
}
void
VerificaNumero
(
int
*
Vetor
,
int
*
Escolhidos
)
{
int
i
,
acertos
;
acertos
=
0
;
for
(
i
=
0
;
i
<
4
;
i
++
)
if
(
PesquisaBinaria
(
Vetor
,
Escolhidos
[
i
])
!=
-
1
)
{
printf
(
"Acertou o Numero %d, Parabéns
\n
"
,
Escolhidos
[
i
]);
acertos
++
;
}
printf
(
"O Total de Acertos foi de: %d
\n
"
,
acertos
);
}
This diff is collapsed.
Click to expand it.
Arquivos/Vetor.c
+
8
−
0
View file @
86ecf216
#include
"Estruturas.h"
void
LerDados
(
int
*
Vetor
)
{
int
i
;
printf
(
"Digite 4 números: "
);
for
(
i
=
0
;
i
<
4
;
i
++
)
scanf
(
"%d"
,
&
Vetor
[
i
]);
}
//Função que gera valores aleatorios para o vetor
void
GeraVetor
(
int
*
Vetor
)
{
int
i
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment