
输入10个同学的成绩输出其中的最高分和最低分(用C语言)用FOR语句
3个回答
展开全部
#include <stdio.h>
void main()
{
int scores[10], highest, lowest, i, j, tmp;
/* 输入十个人的成绩 */
for(i=0; i<10; i++)
{
printf(“请输入第 %d 个同学的成绩: ”, i+1);
scanf(“%d”, &scores[i]);
}
/* 从高到低对分数进行排序 */
for(i=0; i<9; i++)
for(j=i+1; j<10; j++)
if(scores[i] < scores[j])
{
tmp = scores[i];
scores[i] = scores[j];
scores[j] = tmp;
}
/* 最高分 */
highest = scores[0];
/* 最低分 */
lowest = scores[9];
printf("最高分数: %d 分, 最低分数: %d 分", highest, lowest);
}
void main()
{
int scores[10], highest, lowest, i, j, tmp;
/* 输入十个人的成绩 */
for(i=0; i<10; i++)
{
printf(“请输入第 %d 个同学的成绩: ”, i+1);
scanf(“%d”, &scores[i]);
}
/* 从高到低对分数进行排序 */
for(i=0; i<9; i++)
for(j=i+1; j<10; j++)
if(scores[i] < scores[j])
{
tmp = scores[i];
scores[i] = scores[j];
scores[j] = tmp;
}
/* 最高分 */
highest = scores[0];
/* 最低分 */
lowest = scores[9];
printf("最高分数: %d 分, 最低分数: %d 分", highest, lowest);
}
展开全部
#include<stdio.h>
#define N 10
void main()
{ int score[N],high=0,low=0;
int i;
printf("输入%d个学生的成绩:",N);
for(i=0;i<N;i++)
{scanf("%d",&score[i]);
if(high<score[i]) high=score[i];
if(low>score[i]) low=score[i];
}
printf("high=%d,low=%d",high,low);
}
#define N 10
void main()
{ int score[N],high=0,low=0;
int i;
printf("输入%d个学生的成绩:",N);
for(i=0;i<N;i++)
{scanf("%d",&score[i]);
if(high<score[i]) high=score[i];
if(low>score[i]) low=score[i];
}
printf("high=%d,low=%d",high,low);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
这个很容易的啊,我很久没写C的了,只能告诉你流程
定义一个数组,长度10,然后输入分数,对数组进行排序,数组第一个和最后一个就是你要的结果了
定义一个数组,长度10,然后输入分数,对数组进行排序,数组第一个和最后一个就是你要的结果了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询