/*************************************** ************************
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]);
}
}