效果:用户输入数字 不限制
输出:按从小到大的顺序显出
利用指针+循环实现
#define N 10000
main()
{int i,j,a[N],*p,t;
clrscr();
printf("the length of the munbers:\n");
scanf("%d",&i);
printf("put the %d munbers:\n",i);
for(p=a;p<a+i;p++)
scanf("%d",p);
for(j=0;j<i-1;j++)
for(p=a;p<a+i-j-1;p++)
if(*p>*(p+1))
{t=*p;
*p=*(p+1);
*(p+1)=t;}
for(p=a;p<a+i;p++)
printf("%d,",*p);
}
main()
{int i,j,a[N],*p,t;
clrscr();
printf("the length of the munbers:\n");
scanf("%d",&i);
printf("put the %d munbers:\n",i);
for(p=a;p<a+i;p++)
scanf("%d",p);
for(j=0;j<i-1;j++)
for(p=a;p<a+i-j-1;p++)
if(*p>*(p+1))
{t=*p;
*p=*(p+1);
*(p+1)=t;}
for(p=a;p<a+i;p++)
printf("%d,",*p);
}
温馨提示:答案为网友推荐,仅供参考
第1个回答 2007-11-09
用数组吧。不难的。