2021-06-17 09:23

# 求助，c语言编程题不会，哪位大神帮帮忙，跪谢

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

#### 3条回答默认 最新

已采纳

一个二维数组就可以了。然后进行数据比较

``````void main()
{
int score[8][6];
int total[8];
int i,j,t,min,max;
for(i=0;i<8;i++)
{
for(j=0;j<6;j++)
{
score[i][j] = rand()%10+1;
if(j==0)
{
min = score[i][j];
max = score[i][j];
total[i] = score[i][j];
}
else
{
total[i] += score[i][j];
if(min > score[i][j])
min = score[i][j];
if(max < score[i][j])
max = score[i][j];
}
}
total[i] -= min+max;
}
//
int one = 0,two = 0,three = 0;
for(int i=1;i<8;i++)
{
if(a[i] > a[one])
{
three = two;
two = one;
one = i;
}
else if(a[i] > a[two])
{
three = two;
two = i;
}
else if(a[i] > a[three])
three = i;
}
printf("冠军为第%d号歌手，总成绩为:%d\n",one+1,total[one]);
printf("亚军为第%d号歌手，总成绩为:%d\n",two+1,total[two]);
printf("季军为第%d号歌手，总成绩为:%d\n",three+1,total[three]);
}``````
点赞 评论

代码有点错误，以下为最终版本

``````#include <stdlib.h>
void main()
{
int score[8][6];
int total[8];
int i, j, min, max;
for (i = 0; i<8; i++)
{
for (j = 0; j<6; j++)
{
scanf("%d",&score[i][j]);
if (j == 0)
{
min = score[i][j];
max = score[i][j];
total[i] = score[i][j];
}
else
{
total[i] += score[i][j];
if (min > score[i][j])
min = score[i][j];
if (max < score[i][j])
max = score[i][j];
}
}
total[i] -= min + max;
}
//
int one = 0, two = 0, three = 0;
for (int i = 1; i<8; i++)
{
if (total[i] > total[one])
{
three = two;
two = one;
one = i;
}
else if (total[i] > total[two])
{
three = two;
two = i;
}
else if (total[i] > total[three])
three = i;
}
printf("冠军为第%d号歌手，总成绩为:%d\n", one + 1, total[one]);
printf("亚军为第%d号歌手，总成绩为:%d\n", two + 1, total[two]);
printf("季军为第%d号歌手，总成绩为:%d\n", three + 1, total[three]);
}``````
点赞 1 评论
• 53714639 2021-06-30 21:58

这个程序如果1号选手为最高分的话，最后的输出结果有问题呀

点赞 评论