Time Limit: 1000 ms Memory Limit: 32678 KiB
Problem Description
给你N(N<=100)个数,请你按照从小到大的顺序输出。
Input
输入数据第一行是一个正整数N,第二行有N个整数。
Output
输出一行,从小到大输出这N个数,中间用空格隔开。
Sample Input
5
1 4 3 2 5
Sample Output
1 2 3 4 5
Hint
Source
#include <stdio.h>
#include <stdlib.h>
int main()
{
int n,a[101];
int i,j;
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<n-1;i++) //冒泡排序;
{
for(j=0;j<n-i-1;j++)
if(a[j]>a[j+1])
{
int t=a[j];
a[j]=a[j+1];
a[j+1]=t;
}
}
for(i=0;i<n;i++) //输出;
{
if(i==n)
printf("%d\n",a[i]);
else printf("%d ",a[i]);
}
return 0;
}
5
1 4 3 2 5
1 2 3 4 5
Process returned 0 (0x0) execution time : 3.210 s
Press any key to continue.