An example Analysis of C language structure Type Program
This article mainly introduces "C language structure type program example analysis". In daily operation, I believe that many people have doubts about c language structure type program case analysis. The editor has consulted all kinds of data and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "c language structure type program example analysis". Next, please follow the editor to study!
Examples of structural type programs
Example: define a structure type student, including student number, name, grade and average score of 3 courses, a total of 6 members. Define a structural variable, enter the data of the first five members of the student from the keyboard, calculate the average score and output the values of all members.
The reference code is as follows
# include
Struct student / / define the structure type
{
Int id
Char name [20]
Double score1
Double score2
Double score3
Double aver
}
Int main ()
{
Struct student stu
Printf ("input: student ID number name score 1 into é score 2 into é score 3:\ n")
Scanf ("% d%s%lf%lf%lf", & stu.id,stu.name,&stu.score1,&stu.score2,&stu.score3)
Stu.aver= (stu.score1+stu.score2+stu.score3) / 3
Printf ("student ID:% d\ n", stu.id)
Printf ("name:% s\ n", stu.name)
Printf ("score 1% .2f\ n", stu.score1)
Printf ("score 2%. 2f\ n", stu.score2)
Printf ("Grade 3% .2f\ n", stu.score3)
Printf ("GPA:% .2f\ n", stu.aver)
Return 0
}
At this point, the study of "C language structure type program example analysis" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!