码迷,mamicode.com
首页 > 编程语言 > 详细

记录一个班级的成绩练习一维数组

时间:2015-04-08 18:05:26      阅读:155      评论:0      收藏:0      [点我收藏+]

标签:c   实例   数组   

直接上代码,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;
}

下面是我的程序的运行结果:
技术分享

记录一个班级的成绩练习一维数组

标签:c   实例   数组   

原文地址:http://blog.csdn.net/hongbochen1223/article/details/44943471

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!