Last active
July 1, 2016 15:24
-
-
Save phosphore/51fea1bf9526f321fce99bdb3ab06061 to your computer and use it in GitHub Desktop.
This file contains 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> | |
int main() | |
{ | |
FILE* myFile; | |
int i; | |
int j; | |
char filename[35]; | |
int minimo; | |
int massimo; | |
float somma = 0.0, media, trovati; | |
scanf("%s", filename); | |
scanf("%d", &minimo); | |
scanf("%d", &massimo); | |
myFile = fopen(filename, "r"); | |
if (myFile == NULL) { | |
printf("Errore nella lettura del file\n"); | |
exit(0); | |
} | |
fscanf(myFile, "%d", &i); | |
int numberArray[i]; | |
for (j = 0; j < i; j++) { | |
fscanf(myFile, "%d", &numberArray[j]); | |
} | |
for (j = 0; j < i; j++) { | |
if (numberArray[j] < massimo && numberArray[j] > minimo) { | |
trovati++; | |
somma = somma + numberArray[j]; | |
} | |
} | |
media = somma / trovati; | |
printf("Media = %.2f", media); | |
fclose(myFile); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment