Rss & SiteMap

课外天地 李树青 http://www.njcie.com

李树青 论坛 南京 财经 课外天地
共1 条记录, 每页显示 10 条, 页签: [1]
[浏览完整版]

标题:课后作业——学生平均成绩统计

1楼
admin 发表于:2008/12/4 6:30:24

1、基本输入程序
# include <stdio.h>

struct student{
        char number[6];
        char name[10];
        int grade[3];
};

void main()
{
        struct student stus[3];

        int i,j;
        for(i=0;i<3;i++)
        {
                printf("请输入学生学号:\n");
                scanf("%s",stus[i].number);
                printf("请输入学生姓名:\n");
                scanf("%s",stus[i].name);
                for(j=0;j<3;j++)
                {
                        printf("请输入第%d门课程的成绩:\n",j+1);
                        scanf("%d",&stus[i].grade[j]);
                }
        }
        
        for(i=0;i<3;i++)
        {
                printf("第%d个学生的学号是%s,姓名是%s",i+1,stus[i].number,stus[i].name);
        }
}

2、增加对总平均分的统计功能
# include <stdio.h>

struct student{
        char number[6];
        char name[10];
        int grade[3];
};

void main()
{
        struct student stus[3];

        int i,j;
        
        double average;//首先尝试使用int
        
        double total=0;//其次尝试使用int

        for(i=0;i<3;i++)
        {
                printf("请输入学生学号:\n");
                scanf("%s",stus[i].number);
                printf("请输入学生姓名:\n");
                scanf("%s",stus[i].name);
                for(j=0;j<3;j++)
                {
                        printf("请输入第%d门课程的成绩:\n",j+1);
                        scanf("%d",&stus[i].grade[j]);
                }
        };
        
        for(i=0;i<3;i++)
        {
                for(j=0;j<3;j++)
                {
                        total=total+stus[i].grade[j];
                }
        }

        average=total/3/3;
        printf("平均分为%f",average);
}

3、完整的程序
# include <stdio.h>

struct student{
        char number[6];
        char name[10];
        int grade[3];
};

void main()
{
        struct student stus[3];

        int i,j;
        
        double average;//首先尝试使用int
        
        double total=0;//其次尝试使用int

        int maxGrade=0;

        int stuOfMaxGrade=0;

        for(i=0;i<3;i++)
        {
                printf("请输入学生学号:\n");
                scanf("%s",stus[i].number);
                printf("请输入学生姓名:\n");
                scanf("%s",stus[i].name);
                for(j=0;j<3;j++)
                {
                        printf("请输入第%d门课程的成绩:\n",j+1);
                        scanf("%d",&stus[i].grade[j]);
                }
        };
        
        for(i=0;i<3;i++)
        {
                for(j=0;j<3;j++)
                {
                        total=total+stus[i].grade[j];
                }
        }

        average=total/3/3;
        printf("平均分为%f\n",average);

        for(i=0;i<3;i++)
        {
                for(j=0;j<3;j++)
                {
                        if(maxGrade<stus[i].grade[j])
                        {
                                maxGrade=stus[i].grade[j];
                                stuOfMaxGrade=i;        
                        }
                }
        }

        total=0;
        for(j=0;j<3;j++)
        {
                total=total+stus[stuOfMaxGrade].grade[j];
        }

        average=total/3;
        printf("最高分数的学生学号是%s,姓名是%s\n",stus[stuOfMaxGrade].number,stus[stuOfMaxGrade].name);
        for(j=0;j<3;j++)
        {
                printf("第%d门课程的成绩是%d\n",j+1,stus[stuOfMaxGrade].grade[j]);
        }
        printf("该学生的平均成绩是%f\n",average);
}

[此贴子已经被作者于2010-12-13 20:06:22编辑过]
共1 条记录, 每页显示 10 条, 页签: [1]

Copyright ©2002 - 2016 课外天地.Net
Powered By Dvbbs Version 8.3.0
Processed in .04688 s, 2 queries.