帮忙找一下错误

蓝色风X 2011-07-04 09:30:24
2. 根据条件进行学生成绩排名
1) 在函数中进行10个学生成绩从高到低排名 sort(int a[10])
2) 改进第一步的函数为sort(int a[],int n),进行n个学生成绩从高到低排名,
3) 改进第二步的函数为sort(int a[],int n, char style), 将n个学生成绩从高到低排名,排名方式根据sort()函数的style参数进行,如style为‘a’按升序排,style为’d’按降序排。(a:ascending 升,d:descending 降)
#include<stdio.h>
int main ()
{ int sort2(int a[],int n);
int sort1(int a[10]);
int a[10],i,n,b[100];
char style ;
printf("please enter ten students' score :\n");
for(i=0;i<10;i++)
scanf("%d",&a[i]);
sort1(a); /* 1\在函数中进行10个学生成绩从高到低排名*/
for(i=0;i<10;i++)
printf("%d\t",a[i]);
printf("please enter n:\n"); /* 2\n个学生成绩从高到低排名*/
scanf("%d",&n);
printf("please enter %d students' score :\n",n);
for (i=0;i<n;i++)
scanf("%d",&b[i]);
sort2(b,n);
for(i=0;i<n;i++)
printf("%d\t",b[i]);
printf("please enter style a or d :\n"); /*3\按照升序或降序排列*/
style=getchar();
sort2(b,n);
if (style==a)
{
for (i=0;i<n;i++)
printf("%d\n",b[n-1-i]);
}
else if (style='d')
{
for (i=0;i<n;i++)
printf("%d\n",b[i]);
}

}
int sort1(int a[10])
{ int sort2(int a[], int n );
sort2(a,10);
}
int sort2(int a[], int n ) /* Mathematics */
{
int i,j,t;
for (i=0;i<n;i++)
for (j=i+1;j<n;j++)
if (a[i]<a[j])
{t=a[i];a[i]=a[j];a[j]=t;}
}

最后不能输入style就直接跳过了 本来是要按照那个a或者d排列

...全文
68 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
luciferisnotsatan 2011-07-04
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 bdmh 的回复:]

不能输入style,不是你的错,是缓存问题,你在输入style前,加一句 fflush(stdin),清一下缓存
[/Quote]
++
bdmh 2011-07-04
  • 打赏
  • 举报
回复
不能输入style,不是你的错,是缓存问题,你在输入style前,加一句 fflush(stdin),清一下缓存
至善者善之敌 2011-07-04
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 bdmh 的回复:]
不能输入style,不是你的错,是缓存问题,你在输入style前,加一句 fflush(stdin),清一下缓存
[/Quote]

+++1

69,369

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧