Skip to content

Instantly share code, notes, and snippets.

@phosphore
Last active July 1, 2016 15:24
Show Gist options
  • Save phosphore/51fea1bf9526f321fce99bdb3ab06061 to your computer and use it in GitHub Desktop.
Save phosphore/51fea1bf9526f321fce99bdb3ab06061 to your computer and use it in GitHub Desktop.
#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