「已注销」
2021-06-21 11:21
采纳率: 25%
浏览 9

c语言求解答急急急!!

求大佬做个成绩统计器

要求有姓名输入,平均成绩,最高成绩最低成绩,排名,占比。

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • qfl_sdu 2021-06-21 11:31
    已采纳

    代码如下:

    #include <stdio.h>
    struct Student
    {
    	int nmb;
    	char name[20];
    	int score[3];
    };
    //录入数据
    void inputinfo(struct Student a[])
    {
    	int i;
    	printf("输入10个学生的学号,姓名,三门课的成绩:\n");
    	for (i = 0;i< 10;i++)
    	{
    		scanf("%d %s %d %d %d",&a[i].nmb,a[i].name,&a[i].score[0],&a[i].score[1],&a[i].score[2]);
    	}
    }
    //科目成绩最高的学生信息
    void maxinfo(struct Student a[])
    {
    	int i;
    	int max1,max2,max3;
    	int index1 = 0,index2 = 0,index3 = 0;
    	max1 = a[0].score[0];
    	max2 = a[0].score[1];
    	max3 = a[0].score[2];
    	for (i = 1;i<10;i++)
    	{
    		if (a[i].score[0] > max1)
    		{
    			max1 = a[i].score[0];
    			index1 = i;
    		}
    		if (a[i].score[1] > max2)
    		{
    			max2 = a[i].score[1];
    			index2 = i;
    		}
    		if (a[i].score[2] > max3)
    		{
    			max3 = a[i].score[2];
    			index3 = i;
    		}
    	}
    	printf("科目1成绩最高的学生:%d\t%s\t%d\n",a[index1].nmb,a[index1].name,a[index1].score[0]);
    	printf("科目2成绩最高的学生:%d\t%s\t%d\n",a[index2].nmb,a[index2].name,a[index2].score[1]);
    	printf("科目3成绩最高的学生:%d\t%s\t%d\n",a[index3].nmb,a[index3].name,a[index3].score[2]);
    }
    
    //科目成绩最低的学生信息
    void mininfo(struct Student a[])
    {
    	int i;
    	int min1,min2,min3;
    	int index1 = 0,index2 = 0,index3 = 0;
    	min1 = a[0].score[0];
    	min2 = a[0].score[1];
    	min3 = a[0].score[2];
    	for (i = 1;i<10;i++)
    	{
    		if (a[i].score[0] < min1)
    		{
    			min1 = a[i].score[0];
    			index1 = i;
    		}
    		if (a[i].score[1] < min2)
    		{
    			min2 = a[i].score[1];
    			index2 = i;
    		}
    		if (a[i].score[2] < min3)
    		{
    			min3 = a[i].score[2];
    			index3 = i;
    		}
    	}
    	printf("科目1成绩最低的学生:%d\t%s\t%d\n",a[index1].nmb,a[index1].name,a[index1].score[0]);
    	printf("科目2成绩最低的学生:%d\t%s\t%d\n",a[index2].nmb,a[index2].name,a[index2].score[1]);
    	printf("科目3成绩最第的学生:%d\t%s\t%d\n",a[index3].nmb,a[index3].name,a[index3].score[2]);
    }
    
    
    
    
    //平均成绩最高的学生信息
    void avginfo(struct Student a[])
    {
    	int i = 0;
    	float avg = 0.0;
    	float maxavg = (a[0].score[0] + a[0].score[1]+a[0].score[2])/3.0;
    	int index =0;
    	for (i = 1;i<10;i++)
    	{
    		avg = (a[i].score[0] + a[i].score[1]+a[i].score[2])/3.0;
    		if (avg > maxavg)
    		{
    			maxavg = avg;
    			index = i;
    		}
    	}
    	printf("平均分最高的学生:%d\t%s\t%.2f\n",a[index].nmb,a[index].name,maxavg);
    }
    //按平均分从高到低排序
    void Sort(struct Student a[])
    {
    	int i,j;
    	float avg1,avg2;
    	struct Student tmp;
    	for (i = 0;i< 9;i++)
    	{
    		for (j = 0;j< 9-i;j++)
    		{
    			avg1 = (a[j].score[0] + a[j].score[1]+a[j].score[2])/3.0;
    			avg2 = (a[j+1].score[0] + a[j+1].score[1]+a[j+1].score[2])/3.0;
    			if(avg1 < avg2)
    			{
    				tmp = a[j];
    				a[j] = a[j+1];
    				a[j+1] = tmp;
    			}
    		}
    	}
    	printf("number	name	math	Chinese	English	average\n");
    	for (i = 0;i<10;i++)
    	{
    		avg1 = (a[i].score[0] + a[i].score[1]+a[i].score[2])/3.0;
    		printf("%d\t%s\t%d\t%d\t%d\t%.2f\n",a[i].nmb,a[i].name,a[i].score[0],a[i].score[1],a[i].score[2],avg1);
    	}
    }
    
    //统计占比
    void Zhanbi(struct Student a[])
    {
    	int aa = 0,b = 0,c = 0,d = 0;
    	float avg = 0.0;
    	int i = 0;
    	for (i = 0;i<10;i++)
    	{
    		avg = (a[i].score[0] + a[i].score[1] + a[i].score[2]) /3.0;
    		if(avg >=90.0)
    			aa++;
    		else if(avg >= 80.0 && avg <90.0)
    			b++;
    		else if(avg >= 60.0 && avg <80.0)
    			c++;
    		else
    			d++;
    	}
    	printf("平均分90分以上的占比为%.1f\n",aa/10.0);
    	printf("平均分80-90分的占比为%.1f\n",b/10.0);
    	printf("平均分60-80分的占比为%.1f\n",c/10.0);
    	printf("平均分60分以下的占比为%.1f\n",d/10.0);
    }
    
    
    
    
    int main()
    {
    	struct Student a[10];
    	inputinfo(a);
    	maxinfo(a);
    	mininfo(a);
    	avginfo(a);
    	Sort(a);
    	Zhanbi(a);
    	return 0;
    }
    
    点赞 打赏 评论

相关推荐 更多相似问题