c语言求解。 从键盘输入一个正整数N,再输入N个整数,按从小到大的顺序输出。

2024-11-08 03:23:57
推荐回答(4个)
回答1:

#include
main()
{ int a[100],i,j,t,n;
printf("Input N:\n");
scanf("%d",&n);
printf("请再输入%d个数据:",n);
for(i=0;i scanf("%d",&a[i]);
printf("\n");
for(j=0;j for(i=0;i if(a[i]>a[i+1])
{t=a[i]; a[i]=a[i+1]; a[i+1]=t;}
printf("The sorted numbers:\n");
for(i=0;i printf("%d ",a[i]);
}

回答2:

#include
void main()
{
int n,i,j,t,a[10000];
printf("请指竖稿输入正整数N:");
scanf("%d",&n);
printf("请依次纤握输入%d个数",n);
for(i=0;i {
printf("请输入第%d个数",i+1);
scanf("%d",&a[i]);
}
for(j=0;j for(i=0;i if(a[i]>唯孝a[i+1])
{
t=a[i];
a[i]=a[i+1];
a[i+1]=t;
}
printf("排序后数组为");
for(i=0;i printf("%d ",a[i]);

}

回答3:

#include
int main()
{ int n,a[n],i,j,t;
printf("please input a number:");
scanf("%d",&n);
for(i=0;i {printf("please enter n numbers:\n"手腔);
scanf("%d",&a[i]);}
for(j=0;j for(i=0;i if(a[i]>a[i+1])
{ t=a[i];
a[i]=a[i+1];
a[i+1]=t;
}
printf("消谈the sorted numbers:\n");
for(i=0;i printf("%d",a[i]);
printf("\n");
return 0;
}
有些中文毕桥衫符号,你改下,没有试过机。

回答4:

可以用冒泡排序算法