请各位帮忙用C语言编一下程序,其中50位选学生的姓名和成绩都在执行时无需手动输入即可体现在输出结果上的

题目如下:假设一个班有50位学生每位学生有6科成绩,用C语言编一个程序,输出结果为:随机出现50位学生的姓名和他们的各科成绩,但是要组成一个表。格式如下:数学语文英语物理... 题目如下: 假设一个班有50位学生
每位学生有6科成绩,用C语言编一个程序,输出结果为:随机出现50位学生的姓名和他们的各科成绩,但是要组成一个表。格式如下:
数学 语文 英语 物理 化学 生物 平均分 总分
姓名
姓名
姓名
姓名
有50个(但是是随机的)
分数也是随机的(即学生姓名和成绩是可以重复的)
谢谢!急要!
请再将输出结果按总分来降序排列。谢谢!多谢!
展开
 我来答
沧海雄风2009
2011-06-17 · TA获得超过1.1万个赞
知道大有可为答主
回答量:8525
采纳率:79%
帮助的人:2730万
展开全部
编号 数学 语文 英语 物理 化学 生物 平均分 总分
| 0| 14| 71| 95| 41| 49| 71|56.833332|2367460|
| 1| 5| 84| 41| 75| 75| 26|51.000000|2367460|
| 2| 26| 24| 37| 69| 85| 45|47.666668|2367460|
| 3| 86| 40| 23| 50| 67| 92|59.666668|2367460|
| 4| 7| 45| 90| 47| 10| 55|42.333332|2367460|
| 5| 15| 59| 28| 78| 5| 51|39.333332|2367460|
| 6| 4| 90| 99| 80| 61| 36|61.666668|2367460|
| 7| 84| 58| 63| 1| 40| 64|51.666668|2367460|
| 8| 31| 36| 8| 21| 15| 84|32.500000|2367460|
| 9| 9| 60| 99| 52| 79| 87|64.333336|2367460|
|10| 53| 100| 15| 72| 76| 75|65.166664|2367460|
|11| 11| 32| 30| 77| 50| 47|41.166668|2367460|
|12| 96| 39| 48| 40| 29| 96|58.000000|2367460|
|13| 58| 4| 35| 6| 77| 17|32.833332|2367460|
|14| 89| 77| 83| 97| 32| 20|66.333336|2367460|
|15| 11| 9| 72| 22| 26| 3|23.833334|2367460|
|16| 1| 15| 18| 33| 11| 35|18.833334|2367460|
|17| 10| 19| 19| 21| 34| 86|31.500000|2367460|
|18| 68| 12| 8| 35| 52| 74|41.500000|2367460|
|19| 19| 8| 34| 58| 27| 58|34.000000|2367460|
|20| 4| 8| 57| 11| 92| 6|29.666666|2367460|
|21| 61| 76| 73| 21| 73| 29|55.500000|2367460|
|22| 3| 88| 64| 39| 22| 1|36.166668|2367460|
|23| 90| 46| 87| 10| 65| 85|63.833332|2367460|
#include "stdio.h"
#include "string.h"
#include "stdlib.h"
#include "time.h"

struct student
{
char id;
int math;
int chinese;
int english;
int physics;
int chemistry;
int biology;
float average;
int total;
}stu[50];

main()
{
int i,j,k,tmp;
srand((unsigned)time(NULL));
for (i=0;i<50;i++)
{
stu[i].id = i;
stu[i].math = rand()%100+1;
stu[i].chinese = rand()%100+1;
stu[i].english = rand()%100+1;
stu[i].physics = rand()%100+1;
stu[i].chemistry = rand()%100+1;
stu[i].biology = rand()%100+1;
stu[i].total = stu[i].math + stu[i].chinese + stu[i].english + stu[i].physics + stu[i].chemistry + stu[i].biology;
stu[i].average = (float)stu[i].total/6;

}
printf("编号\t数学\t语文\t英语\t物理\t化学\t生物\t平均分\t总分\n");
for (i=0;i<50;i++)
{
printf("|%2d|%7d|%7d|%7d|%7d|%7d|%7d|\t%5.2f|%6d|\n",
stu[i].id,stu[i].math,stu[i].chinese,stu[i].english,stu[i].physics,stu[i].chemistry,stu[i].biology,
stu[i].average,stu[i].total);
}
}
追问
请问一下将输出结果按总分来降序排列是怎样编写的?谢谢!
追答
好了 自己试试  随机生成名字的也弄好了 现在按总分降序排列
#include "stdio.h"
#include "string.h"
#include "stdlib.h"
#include "time.h"
#define N 50

struct student
{
char name[3];
int math;
int chinese;
int english;
int physics;
int chemistry;
int biology;
float average;
int total;
}stu[N];

main()
{
int i,j,k,tmp,Total[N];
srand((unsigned)time(NULL));
for (i=0;i<N;i++)
{
for (j=0;j<3;j++)
{
stu[i].name[j] = rand()%26 + 'A';
}
stu[i].math = rand()%100+1;
stu[i].chinese = rand()%100+1;
stu[i].english = rand()%100+1;
stu[i].physics = rand()%100+1;
stu[i].chemistry = rand()%100+1;
stu[i].biology = rand()%100+1;
stu[i].total = stu[i].math + stu[i].chinese + stu[i].english + stu[i].physics + stu[i].chemistry + stu[i].biology;
stu[i].average = (float)stu[i].total/6;
Total[i] = stu[i].total;
}
printf("\n自动生成。未排序:\n");
printf("\n 姓名 数学 语文 英语 物理 化学 生物 平均分 总分\n");
for (i=0;i<N;i++)
{
printf("| %s |%3d |%3d |%3d |%3d |%3d |%3d | %5.2f | %3d |\n",
stu[i].name,stu[i].math,stu[i].chinese,stu[i].english,stu[i].physics,stu[i].chemistry,stu[i].biology,
stu[i].average,stu[i].total);
}

for (i=0;i<N-1;i++)
{
for (j=0;j<N-i-1;j++)
{
if (stu[j].total<stu[j+1].total)
{
tmp = stu[j].total;
stu[j].total = stu[j+1].total;
stu[j+1].total = tmp;
}
}
}
printf("\n自动生成。按总分降序排序后:\n");
printf("\n 姓名 数学 语文 英语 物理 化学 生物 平均分 总分\n");
for (i=0;i<N;i++)
{
printf("| %s |%3d |%3d |%3d |%3d |%3d |%3d | %5.2f | %3d |\n",
stu[i].name,stu[i].math,stu[i].chinese,stu[i].english,stu[i].physics,stu[i].chemistry,stu[i].biology,
stu[i].average,stu[i].total);
}
}
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式