1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
#include<stdio.h>
#include<math.h>
int readvalues(FILE* fin, float *x);
void range(float *x, int n, float *pmin, float *pmax);
int main(void)
{
float x[100];
float pmin, pmax;
int n;
FILE* fin= fopen("samplesin.txt","r");
FILE* fout= fopen("maxminout.txt","w");
readvalues(fin,x);
range (x, n, &pmin, &pmax);
fprintf(fout,"There are %d values in the array\n", n);
fprintf(fout,"The maximum value in the array is %f\n", pmax);
fprintf(fout,"The minimum value in the array is %f\n", pmin);
fclose(fin);
fclose(fout);
system("pause");
return 0;
}
int readvalues(FILE* fin, float *x){
int n;
while (fscanf(fin, "%d", n) !=EOF){
n++;}
return n;
}
void range(float *x, int n, float *pmin, float *pmax){
float answer_1, answer_2;
int i;
if(x[i]>answer_1){
answer_1 = x[i];
}
if(x[i]<answer_2){
answer_2 = x[i];}
*pmin = answer_1;
*pmax = answer_2;
return;
}
|