diff --git a/Arquivos/Loteria b/Arquivos/Loteria index b52911213aedbde8b1ac3673e0efb962f1f54eff..fe40f16d2243958a4fd7d8feb3359288be132722 100755 Binary files a/Arquivos/Loteria and b/Arquivos/Loteria differ diff --git a/Arquivos/Main.c b/Arquivos/Main.c index dfa2b88ce4e929e61f3fc39723cbdb380a6d2d94..444b09e27fd89515b55dc0d5683bd07854887d57 100644 --- a/Arquivos/Main.c +++ b/Arquivos/Main.c @@ -1,14 +1,19 @@ #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); } diff --git a/Arquivos/Pesquisa.c b/Arquivos/Pesquisa.c index f82e802206b8cc76746bdda12c347bdb250623bc..9614da9fae7326a78558b7c86ba60f1ae45da185 100644 --- a/Arquivos/Pesquisa.c +++ b/Arquivos/Pesquisa.c @@ -1 +1,34 @@ //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); +} diff --git a/Arquivos/Vetor.c b/Arquivos/Vetor.c index 16400e3a8f34fc59d183fe477484ee9372be3134..30c6fb824e63f3606e53560ab3bc561f1879b41d 100644 --- a/Arquivos/Vetor.c +++ b/Arquivos/Vetor.c @@ -1,5 +1,13 @@ #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;