记录一个班级的成绩练习一维数组
生活随笔
收集整理的這篇文章主要介紹了
记录一个班级的成绩练习一维数组
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
直接上代碼,mark一下:嘿嘿
#include <stdio.h>/*** 記錄并統計一個班的學生的成績來* 練習一維數組的使用*/ int main(void) {int count;printf("How many students are in your class?\n");scanf("%d",&count); //獲取班級中學生的數量/*** 我在書中看的說是不允許變量賦值來這,但是* 在我的嘗試中是可以的,不知道怎么回事。*/int numbers[count],chinese[count],maths[count],eng[count];puts("Please input the StudentID and three scores:\n");printf(" studentID Chinese Math English\n");int i = 0;/*** 接受用戶的成績輸入*/for(i = 0;i < count;i++){printf("No.%d>",i+1);scanf("%d %d %d %d",&numbers[i],&chinese[i],&maths[i],&eng[i]);}/*** 輸入完畢之后,輸出用戶的成績及其平均成績*/printf("ID CH MA EN AVE\n");printf("--------------------------\n");int j;for(j = 0;j < count;j++){float ave = (chinese[j] + maths[j] + eng[j])/3; //求出平均成績printf("%d\t%d\t%d\t%d\t%f\n",numbers[j],chinese[j],maths[j],eng[j],ave);}/*** 循環求出各科的總成績*/float ave_chinese = 0,ave_math= 0 ,ave_english = 0;int m;for(m = 0;m < count;m++){ave_chinese += chinese[m];ave_math += maths[m];ave_english += eng[m];}//輸出平均成績printf("The Average of Chinese in this class is %f\n",ave_chinese/count);printf("The Average of math in this class is %f\n",ave_math/count);printf("The Average of english in this class is %f\n",ave_english/count);return 0; }下面是我的程序的運行結果:
轉載于:https://www.cnblogs.com/bobo1223/p/7287637.html
總結
以上是生活随笔為你收集整理的记录一个班级的成绩练习一维数组的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: SpringMVC根据客户端的不同的请求
- 下一篇: Oracle在Linux平台“静默”安装