code doesn't work as expected
Hi guys,
I'm trying to figure this out. After I input numbers the "max" & "min" won't display the correct numbers. Could you tell me how to fix it?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
#include<stdio.h>
#include<conio.h>
int main(){
float a[4][5],min[4],max[4];
for (int i = 0; i <= 3; ++i){
printf("\nInput %d: ",i+1);
for (int j = 0; j <= 4; ++j)
scanf_s("%f",&a[i][j]);
}
for (int i = 0; i < 5; ++i){
max [i] = min[i] = a[0][i];
for (int j = 0; j < 4; ++j){
if (max [i] < a[j][i])
max [i] = a[j][i];
if (min [i] > a[j][i])
max [i] = a[j][i];
printf(" %.2f ", a[j][i]);
}
printf(" max = %.2f min = %.2f\n", max [i], min[i]);
}
_getch();
}
|
Line 17. max or min?
Lines 5 and 11. How many elements do min and max require?
Topic archived. No new replies allowed.