Question 16: each student's student ID, name, C ++, high number, and English score define an array of student scores.

Source: Internet
Author: User

/*************************************** ************************
C Language

AUTHOR: liuyongshui
**************************************** ***********************/
/*
Question 16: each student's student ID, name, C ++, high number, and English score define an array of student scores, the data members include student ID (char num [12]), name (name), grade, total score, and average )).
(1) enter the information of five students on the keyboard;
(2) calculate the total score and average score of each student, and store them in the struct array (you can calculate the total score by the way during the reading process );
(3) Calculate the student ID, name, total score, and average score of each student.
*/

# Include <stdio. h>

Struct stu
{
Char num [12];
Char name [15];
Float cpp;
Float english;
Float math;
Float score;
Float average;
};
Void calculate (struct stu schlastic []); // calculate the total score and average score of Students

Int main ()
{
Int I;
Struct stu student [5];

Printf ("enter the information of five students... \ n ");
Printf ("student ID \ t name \ t English Score \ t High \ tC ++ Score \ n ");
For (I = 0; I <5; I ++)
{
Scanf ("% s % f", student [I]. num,
Student [I]. name, & student [I]. english,
& Student [I]. math, & student [I]. cpp );
}
Calculate (student );

Return 0;
}


// Function Definition
 
Void calculate (struct stu scholatic [])
{
Int I;

For (I = 0; I <5; I ++)
{
Scholatic [I]. score = scholatic [I]. average = 0.0;

Scholatic [I]. score = scholatic [I]. math +
Scholatic [I]. english +
Scholatic [I]. cpp;

Scholatic [I]. average = scholatic [I]. score/3;
}
Printf ("output the total score and average score of each student: \ n ");
For (I = 0; I <5; I ++)
{
Printf ("% d student: Student ID: % s name: % s total score: % f average score: % f \ n", I + 1, scholatic [I]. num,
Scholatic [I]. name,
Scholatic [I]. score,
Scholatic [I]. average );
}
}

 

Related Article

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.