I have been interested in Embedded underlying development, but the foundation is really weak. I bought an embedded entry book and did not find the answers to the exercises in the book. So I am ready to implement it myself. I hope to share my blog with you to discuss progress. Because the content is very basic, don't laugh at it.
Questions: there are 10 students. Each student's data includes student ID, name, and scores of five courses. Enter students' scores on the keyboard and calculate the average scores of five courses, the student ID, name, score, and average score of the five courses are displayed.
# Include <stdio. h ># define N 10 struct {int number; char name [20]; float scores [5]; float average;} student [N]; void printfinfo (INT index ); int main () {for (INT I = 0; I <n; I ++) {float totle = 0.0; printf ("number :"); scanf ("% d", & Student [I]. number); printf ("name:"); scanf ("% s", & Student [I]. name); printf ("scores:"); For (Int J = 0; j <5; j ++) {scanf ("% F", & Student [I]. scores [J]); totle + = student [I]. scores [J];} student [I]. average = totle/3;} int maxindex, minindex = 0; int cur = 0; float Max, min = student [0]. average; while (cur <n) {If (max <student [cur]. average) {max = student [cur]. average; maxindex = cur;} else if (min> Student [cur]. average) {min = student [cur]. average; minindex = cur;} cur ++ ;} printf ("**************** the max student infomation **************** \ n" ); printfinfo (maxindex ); printf ("*************** the min student infomation ***************** \ n" ); printfinfo (minindex);} void printfinfo (INT index) {printf ("number is % d \ n", student [Index]. number); printf ("name is % s \ n", student [Index]. name); printf ("scores is: \ n"); For (Int J = 0; j <5; j ++) {printf ("% F ", student [Index]. scores [J]);} printf ("\ n"); printf ("averages is % F \ n", student [Index]. average); printf ("\ n ");}
Conclusion: The function declaration is used to ensure that the order of functions can be ignored when functions are called each other. In addition, knowledge about struct arrays is used. In general, it is very basic.