Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- // ESSE PROGRAMA IRA LER N NUMEROS DE UM ARQUIVO E MOSTRAR O MAIOR DELES
- int main()
- {
- int i = 0, j = 0, maior, menor;
- FILE *arquivo;
- arquivo = fopen("numeros.txt", "r");
- if (arquivo == NULL)
- {
- printf("Arquivo nao encontrado ! \n");
- return 0;
- }
- while (!feof(arquivo))
- {
- int aux;
- fscanf(arquivo, "%d", &aux);
- i++;
- }
- rewind(arquivo);
- int vetor[i];
- printf("Esse arquivo possui %d numeros \n ", i);
- printf("São eles abaixo: \n");
- while (!feof(arquivo))
- {
- fscanf(arquivo, "%d", &vetor[i]);
- printf("%d \t", vetor[i]);
- }
- printf("\n");
- maior = vetor[0];
- menor = vetor[0];
- for (j = 0; j < i; j++)
- {
- if (vetor[i] > maior)
- maior = vetor[i];
- if (vetor[i] < menor)
- menor = vetor[i];
- }
- printf("Menor %d \n", menor);
- printf("Maior: %d\n", maior);
- fclose(arquivo);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement