Question 11: five students took three courses to program their total scores and average scores (completed in a two-dimensional array ).

Source: Internet
Author: User

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

AUTHOR: liuyongshui
DATE :********
Problem Source: http://blog.csdn.net/sxhelijian/article/details/8620846
**************************************** ***********************/
/*
Question 11: five students took three courses to program their total scores and average scores (completed in a two-dimensional array ).

*/

# Include <stdio. h>

# Define NUM_STUDENTS 5
# Define NUM_COURSE 3

Int I; // defined as a global variable
Int j;

Void calculate (const float score [] [3]);

Int main ()
{
Float result [NUM_STUDENTS] [NUM_COURSE];

Printf ("Enter the scores of five students for the three courses (written in five lines): \ n ");

For (I = 0; I <NUM_STUDENTS; I ++)
{
For (j = 0; j <NUM_COURSE; j ++)
{
Scanf ("% f", & result [I] [j]);
}
}

Calculate (result); // calculate the total score and average score

Return 0;
}


// Function Definition
Void calculate (const float score [] [NUM_COURSE])
{
Float average [NUM_STUDENTS] = {0}; // defines the average score array and assigns all values to 0.
Float sum [NUM_STUDENTS] = {0}; // defines the total score array and assigns all values to 0.

For (I = 0; I <NUM_STUDENTS; I ++)
{
For (j = 0; j <NUM_COURSE; j ++)
{
Sum [I] + = score [I] [j]; // calculates the total score of the I-th student.
}
Average [I] = sum [I]/NUM_STUDENTS; // calculate the average score of the I-th Student
}

For (I = 0; I <NUM_STUDENTS; I ++) // outputs the total score and average score of each student.
{
Printf ("total score of % d is % f, average score is % f \ n", I + 1, sum [I], average [I]);
}
}
 

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.