Introduction to Linux C Programming

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.