The data structure teacher assigned a assignment to count the scores of all the students, and output the information of the highest and total scores of the students in a single subject. It took half a day to write two programs.
I still feel very bad. I have not learned enough.
# Include <stdio. h> <br/> # define N 3 <br/> struct student <br/>{< br/> long num; <br/> char name [20]; <br/> float score [3]; <br/>} data [N]; </P> <p> // Input Function <br/> struct student * input () <br/> {<br/> struct student * P, * head; <br/> int I, j; <br/> P = head = data; <br/> for (I = 0; I <n; I ++, P ++) <br/>{< br/> printf ("Enter the student ID of student % d:", I + 1 ); <br/> scanf ("% lD", & P-> num); <br/> printf ("enter the name of student % d :", I + 1); <br/> scanf ("% s", p-> name); <br/>}< br/> for (j = 0; j <3; ++ J) <br/>{< br/> printf ("Enter the subject % d score:", J + 1 ); <br/> scanf ("% F", & P-> score [J]); <br/>}< br/> return head; <br/>}</P> <p> // query the maximum score function of a single subject <br/> struct student * course_max (struct student * head, int I) <br/>{< br/> float Max; <br/> Int J; <br/> struct student * P, * temp; <br/> P = temp = head; <br/> for (j = 0, max = p-> score [I]; j <n; ++ J, + + p) <br/> If (max <p-> score [I]) <br/> {<br/> max = p-> score [I]; <br/> temp = P; <br/>}< br/> return temp; <br/>}</P> <p> // function for finding the highest score of the total score <br/> struct student * sum_max (struct student * head) <br/>{< br/> float sum, sum_temp; <br/> int I; <br/> struct student * P, * temp; <br/> P = temp = head; <br/> sum = p-> score [0] + P-> score [1] + P-> score [2]; <br/> P ++; <br/> for (I = 1; I <n; I ++, P ++) <br/> {<br/> sum_temp = p-> score [0] + P-> score [1] + P-> score [2]; <br/> If (sum <sum_temp) <br/>{< br/> sum = sum_temp; <br/> temp = P; <br/>}< br/> return temp; <br/>}</P> <p> int main () <br/> {<br/> struct student * head; <br/> struct student * max; <br/> int I, J; <br/> struct student * point [3]; <br/> head = input (); <br/> for (I = 0; I <3; ++ I) <br/> point [I] = course_max (Head, I); <br/> max = sum_max (head); <br/> printf ("Student Information: /n "); <br/> for (I = 0; I <n; I ++, head ++) <br/>{< br/> printf ("%-10ld %-10 s", head-> num, head-> name ); <br/> for (j = 0; j <3; j ++) <br/> printf ("% 10.1f", head-> score [J]); <br/> printf ("/N"); <br/>}< br/> for (I = 0; I <3; ++ I) <br/> {<br/> printf ("/n subject % d highest score student information:/n %-10ld %-10 s", I + 1, point [I]-> num, point [I]-> name); <br/> for (j = 0; j <3; ++ J) <br/> printf ("% 10.1f", point [I]-> score [J]); <br/>}< br/> printf ("/N has the highest total score of students:/n %-10ld %-10 s", Max-> num, max-> name); <br/> for (j = 0; j <3; ++ J) <br/> printf ("% 10.1f ", max-> score [J]); <br/> printf ("/n"); <br/> return 0; <br/>}
This is the first time I wrote this article. Because I had to submit a job, it took me one hour to write it in a hurry.
When outputting student information, if two students with the same highest score are met, only the first highest score student information can be output.
# Include <stdio. h> <br/> # define Stu 3 // Stu indicates the total number of students. <Br/> # define cou 3 // cou indicates the total number of subjects. <Br/> struct student <br/> {<br/> long num; <br/> char name [20]; <br/> float score [cou]; // record the score of each subject <br/> float score_sum [cou]; // record the total score of each student <br/>} data [STU]; </P> <p> // input information function. <br/> struct student * input () <br/> {<br/> struct student * P, * head; <br/> int I, J; <br/> P = head = data; <br/> for (I = 0; I <Stu; I ++, P ++) <br/>{< br/> printf ("Enter the student ID of student % d:", I + 1 ); <br/> scanf ("% lD", & P-> num); <br/> printf ("enter the name of student % d: ", I + 1); <br/> scanf (" % s ", p-> name); <br/>}< br/> for (j = 0; j <3; ++ J) <br/>{< br/> printf ("Enter the subject % d score:", J + 1 ); <br/> scanf ("% F", & P-> score [J]); <br/>}< br/> return head; <br/>}< br/> // output overall information function <br/> void output (struct student * head) <br/>{< br/> struct student * P; <br/> int I, j; <br/> P = head; <br/> printf ("/n student information:/n"); <br/> for (I = 0; I <Stu; ++ I, ++ p) <br/>{< br/> printf ("% 10ld % 10 s", p-> num, p-> Nam E); <br/> for (j = 0; j <cou; ++ J) // This cycle outputs the cou score <br/> printf ("% 10.1f", p-> score [J]); <br/> printf ("/N"); <br/>}</P> <p> // calculate the maximum score function of a single subject. <Br/> void course_max (struct student * head, int I) // I is the number of subjects. <Br/> {<br/> struct student * P; <br/> float max = 0; <br/> Int J, K; <br/> for (j = 0, P = head; j <Stu; ++ J, ++ P) <br/> If (max <p-> score [I]) <br/> max = p-> score [I]; // find the highest score <br/> printf ("/n subject % d the highest score student information is:/n", I + 1 ); <br/> for (j = 0, P = head; j <Stu; ++ J, ++ P) <br/> {<br/> If (max = p-> score [I]) // output students with the same highest score <br/>{< br/> printf ("% 10ld % 10 s", p-> num, p-> name ); <br/> for (k = 0; k <cou; ++ K) <br/> printf ("% 10.1f", p-> score [k]); <br/> printf ("/N "); <br/>}</P> <p> // calculate the total score function of a single student <br/> void score_sum (struct student * Head) <br/>{< br/> int I, j; <br/> struct student * P; <br/> P = head; <br/> P-> score_sum [0] = 0; <br/> for (I = 0; I <Stu; ++ I, ++ P) <br/> for (j = 0; j <cou; ++ J) <br/> P-> score_sum [I] + = p-> score [J]; <br/>}</P> <p> // calculate the highest score function <br/> void sum_max (struct student * head) <br/>{< br/> float max = 0; <br/> int I, j; <br/> struct student * P; <br/> for (I = 0, P = head; I <Stu; ++ I, ++ P) <br/> If (max <p-> score_sum [I]) <br/> max = p-> score_sum [I]; // find the highest score in the total score <br/> printf ("/n total score student information:/n"); <br/> for (I = 0, P = head; I <Stu; ++ I, ++ p) <br/> {<br/> If (max = p-> score_sum [I]) // output the student information equivalent to the highest score of the total score <br/>{< br/> printf ("% 10ld % 10 s", p-> num, p-> name ); <br/> for (j = 0; j <cou; ++ J) <br/> printf ("% 10.1f", p-> score [J]); <br/> printf ("/N"); <br/>}</P> <p> int main (void) <br/>{< br/> int I; <br/> struct student * head; <br/> head = input (); <br/> output (head ); <br/> for (I = 0; I <cou; ++ I) <br/> course_max (Head, I); <br/> score_sum (head ); <br/> sum_max (head); <br/> printf ("/N"); <br/> return 0; <br/>}
Then I wrote it again to solve the problem that I could not output it multiple times. I haven't thought of other problems yet. Post it first and leave it for future improvement.
I don't know how it will feel if I look at these codes in five years.