-----------android培训、java培训、java学习型技术博客、期待与您交流!------------
直接上代码了,注释用英文标注的,可能表示有误,是为了练习英文注释的习惯。
#include <stdio.h> /** * import how many students in class. * * @return the students' number. */ int studentNum(){ int num; printf("please import the student's number:\n"); scanf("%d",&num); return num; } /** * import the every student;'s score. * * @param a put student's score in a array. * @param studentNum number of student */ void importScore(int a[],int studentNum){ for (int i=0; i<studentNum; i++) { printf("please import the %d's student's score:\n",i+1); scanf("%d",&a[i]); } } /** * caculate student's score of total. * * @param a put student's score in a array. * @param studentNum number of student * * @return student's score of total. */ int scoreSum(int a[],int studentNum){ int sum = 0; for (int i=0; i<studentNum; i++) { sum = a[i]+sum; } return sum; } /** * caculate the student's score of average. * * @param sum the student's score of total. * @param studentNum number of student. */ void scoreAverage(int sum,int studentNum){ int average = sum/studentNum; printf("the student's average is %d\n",average); } int main(){ int number = studentNum(); int a[number]; int sum; importScore(a, number); sum = scoreSum(a, number); scoreAverage(sum, number); }