Created
May 27, 2013 03:54
-
-
Save hugogrochau/5655113 to your computer and use it in GitHub Desktop.
Questão 2 da P2 antiga
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#define ARQUIVO "QUALIDADE.TXT" | |
#define TAM_MIN 25 | |
#define TAM_MAX 44 | |
#define TAM (TAM_MAX - TAM_MIN + 1) | |
void preenche_vetores(float[], float[], int); | |
int main(void) { | |
float Min[TAM], Max[TAM], comp; | |
int tam, i, indice, Reprovados[TAM], Aprovados[TAM]; | |
/* inicializando os vetores com 0s */ | |
for (i = 0; i < TAM; i++) { | |
Reprovados[i] = 0; | |
Aprovados[i] = 0; | |
} | |
preenche_vetores(Min, Max, TAM); | |
while (1) { /* while infinito até um 'break' */ | |
printf("Tamanho e comprimento:"); | |
scanf("%d %f", &tam, &comp); | |
if (tam < TAM_MIN || tam > TAM_MAX) | |
break; /* se o tamanho for invalido, sai do while */ | |
indice = tam - TAM_MIN; | |
if (comp >= Min[indice] && comp <= Max[indice]) | |
Aprovados[indice]++; | |
else | |
Reprovados[indice]++; | |
} | |
for (i = 0; i < TAM; i ++) | |
printf("\nTamanho %d:\nAprovados: %d\nReprovados: %d\n", i + TAM_MIN, Aprovados[i], Reprovados[i]); | |
return 0; | |
} | |
void preenche_vetores(float Min[], float Max[], int n) { | |
int i; | |
FILE *fp = fopen(ARQUIVO, "r"); | |
if (!fp) { | |
printf("Erro ao abrir o arquivo\n"); | |
exit(1); | |
} | |
for (i = 0; i < n; i++) | |
fscanf(fp, "%f %f", &Min[i], &Max[i]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment