Skip to content
Snippets Groups Projects
Commit 3e656917 authored by Fernando Erd's avatar Fernando Erd :ok_hand:
Browse files

Select Sort, Gerar Aleatorios, Imprime Vetor

parent eb4338d0
Branches
No related tags found
No related merge requests found
//Arquivo que contém os defines e os registros //Arquivo que contém os defines e os registros
#define TAM 20 //tamanho do vetor #include <stdio.h>
#define MAX 50 //constante que tem o máximo de valores #include <time.h>
#include <stdlib.h>
#define TAM 15 //tamanho do vetor
#define NUMMAX 50 //constante que tem o máximo de valores
File added
#include "Estruturas.h"
int main () {
int Vetor[TAM];
GeraVetor(Vetor);
ImprimeVetor(Vetor);
SelectSort (Vetor);
ImprimeVetor (Vetor);
}
//Aqui a main do trabalho
//Arquivo que ira conter os Algoritmos de ordenação //Arquivo com os Algoritmos de Ordenação
#include "Estruturas.h"
void Troca (int *Vetor, int i, int j) {
int aux;
aux = Vetor[i];
Vetor [i] = Vetor[j];
Vetor [j] = aux;
}
void SelectSort (int *Vetor) {
int i, j, menor;
for (i = 0; i < TAM - 1; i++) {
menor = i;
for (j = i + 1; j < TAM; j++)
if (Vetor[menor] > Vetor[j])
menor = j;
Troca (Vetor, i, menor);
}
}
//Vai contém os algoritmos de busca //Arquivo com os algoritmos de busca
//Funções do vetor #include "Estruturas.h"
//Função que gera valores aleatorios para o vetor
void GeraVetor (int *Vetor) {
int i;
srand (time(NULL));
for (i=0; i < TAM; i++)
Vetor[i] = rand () % NUMMAX;
}
//Função que imprime o vetor
void ImprimeVetor (int *Vetor) {
int i;
printf ("Pos: ");
for (i=0; i < TAM; i++)
printf ("\t%d", i);
printf ("\n");
printf ("Num: ");
for (i=0; i < TAM; i++)
printf ("\t%d", Vetor[i]);
printf ("\n");
}
all:
gcc -c Vetor.c
gcc -c Ordenação.c
gcc -c Pesquisa.c
gcc -c Main.c
gcc Vetor.o Ordenação.o Main.o Pesquisa.o -o Loteria -g
rm *.o
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment