c语言如何输入一个正整数N,再输入N个整数,按从小到大的顺序输出?

2024-11-01 23:44:00
有3个网友回答
网友(1):

#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]);

}

网友(2):

#include

int main()

{int n,i,j,t,a[200];

scanf("%d",&n);

for(i=0;i

scanf("%d",&a[i]);

for(i=0;i

for(j=0;j

if(a[j]>a[j+1])

{t=a[j];a[j]=a[j+1];a[j+1]=t;}

for(i=0;i<简哗n;i++)

printf("敏模%d ",a[i]);

printf("\n");

return 拦拿行0;

}

网友(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;
}
有些中文毕桥衫符号,你改下,没有试过机。