排序题

题目描述:

    对输入的n个数进行排序并输出。

输入:

    输入的第一行包括一个整数n(1<=n<=100)。
    接下来的一行包括n个整数。

输出:

    可能有多组测试数据,对于每组数据,将排序后的n个整数输出,每个数后面都有一个空格。
    每组测试数据的结果占一行。

样例输入:
4
1 4 3 2
样例输出:
1 2 3 4 


源码:
 1 #include <stdio.h>
 2 
 3 int main()
 4 {
 5     int n, a[100];
 6     int i, j, t;
 7     while(scanf("%d",&n) != EOF){
 8         
 9         for(i = 0; i < n; i++){
10                 scanf("%d", &a[i]);
11             }
12             for(i = 0; i < n-1; i++){
13                 for(j = 0; j < n-1; j++){
14                     if(a[j] > a[j+1]){
15                         t = a[j];
16                         a[j] = a[j + 1];
17                         a[j+1] = t;
18                     }
19                 }
20             }
21                 for(i = 0; i < n; i++){
22                     printf("%d ",a[i]);
23                 }
24         printf("
");    
25     }
26     
27     return 0;
28 }

普通排序,这个是冒泡。

Everything will be ok in the end. If it is not ok then it is not the end.
原文地址:https://www.cnblogs.com/shirleytian/p/3310686.html