1119: 一维数组排序

题目描述

对一维数组按照从小到大的顺序排序。程序定义函数sort()来实现数组a的排序。函数原型如下:

void sort(int a[], int n);

数组元素的输出调用PrintArr()。

输入

第一行输入一个整数n(1<=n<=10),表示数组有n个整数;第二行输入n个整数。

输出

输出占一行。对这n个整数数按照从小到大的顺序输出,数据之间用一个空格隔开。

样例输入

6
6 5 1 2 3 4

样例输出

1 2 3 4 5 6
#include<stdio.h>
#include <algorithm>
using namespace std;
int main()
{
    int a[10];
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        
    }
    sort(a,a+n);
    for(int i=0;i<n;i++)
    {
        if(i==0)
    printf("%d",a[i]);
        else
    printf("% d",a[i]);
        
    }
    
    return 0;
}
原文地址:https://www.cnblogs.com/binanry/p/10055274.html