Anda di halaman 1dari 2

5.

1
9.2
6.2
2.4

3.2
1.0
7.7
3.6

6.7
3.5
8.1
0.7

8.0
4.5
8.8
9.0

void functionavg(float c[][4]);


void functionlargest(float a[][4]);
void functionsmallest(float b[][4]);
int main(void){
FILE *cfptr;
float array[4][4] = { 0 };
size_t j;
size_t i;
if ((cfptr = fopen("c.dat", "r")) == NULL){
printf("The file cannot be opened.\n");
}
else{
for (j = 0; j < 4; j++){
for (i = 0; i < 4; ++i){
fscanf(cfptr, "%f", &array[j][i]);
printf("%.2f\n", array[j][i]);
}
}
functionlargest(array);
functionsmallest(array);
functionavg(array);
}
}
void functionlargest(float a[][4]){
float max[4];
size_t k;
size_t j;
for (k = 0; k < 4; ++k){
max[k] = a[k][0];
for (j = 0; j < 4; ++j){
if (max[k] < a[k][j])
max[k] = a[k][j];
}
}
puts("");
for (k = 0; k < 4; ++k){
printf("%d\t%f\n", k, max[k]);
}
}
void functionsmallest(float b[][4]){
float small[4];
size_t t;
size_t i;
for (t = 0; t < 4; ++t){
small[t] = b[t][0];
for (i = 0; i < 4; ++i){
if (small[t]>b[t][i])
small[t] = b[t][i];
}
}
puts("");

for (t = 0; t < 4; ++t){


printf("%d\t%f\n", t, small[t]);
}
}
void functionavg(float c[][4]){
float sum[4] = { 0 };
size_t t;
size_t i;
for (t = 0; t < 4; ++t){
for (i = 0; i < 4; ++i){
sum[t] = sum[t] + c[t][i];
}
}
puts("");
for (t = 0; t < 4; ++t){
printf("%d\t%f\n", t, sum[t] / 4);
}
}

Anda mungkin juga menyukai