Home > Back-end >  The c language
The c language

Time:10-02

Have a great god help me to look at my code exactly what went wrong ah second printf print out

#include
20 # define m
Void main ()
{
Char id [m];
Char name [m];
Float a, [m].
Float b [m];
Float c [m];
Int I, n, k=0;
Float s1=0, s2=0, s3=0;
Float sum1=0, sum2=0;
The scanf (" % d ", & amp; n);
for(i=0; i{the scanf (" % s % s % f % f % f ", & amp; Id [I], & amp; The name [I], & amp; A [I], & amp; [I], b & amp; [I] c);
}
for(i=0; i{s1 +=a, [I]. S2 +=b [I]; S3 +=c [I];
}
for(i=0; i{sum1=a + b + c [I] [I] [I]; If (sum1 & gt; Sum2) {sum2=sum1; K=I; }
}
Printf (" % % 1 f, % 1 f, 1 f \ n ", s1/n, s2/n, s3/n);
Printf (" % s % s % % 1 f, % 1 f, 1 f \ n ", id [k], the name [k], a [k], [k], b c [k]);
}

CodePudding user response:

Char id [m];
Char name [m];
The two character array can store n a student's name and student id?
Suggested that students with structure array to store information

CodePudding user response:

Char id [m];
Char name [m];
Here is wrong, two id, if id is not a number, should be a two dimensional array id [2] [m]. The name [2] [m].
Here the wrong cause you output
Printf (" % s % s % % 1 f, % 1 f, 1 f \ n ", id [k], the name [k], a [k], [k], b c [k]); Here also wrong
Should be printf (" % s % s %. 1 f %. 1 f %. 1 f \ n ", & amp; Id [k] [0], & amp; The name [k] [0], a [k], [k], b c [k]);

for(i=0; i{sum1=a + b + c [I] [I] [I]; If (sum1 & gt; Sum2) {sum2=sum1; K=I; }
}
Here is wrong, two are in sum1 to calculate the total score,



Two id should be a two dimensional array
  • Related