Description
对一维数组按照从小到大的顺序排序。程序定义函数sort()来实现数组a的排序。函数原型如下:
int sort(int a[], int n);
数组元素的输出调用PrintArr()。
Input
第一行输入一个整数n(1<=n<=10),表示数组有n个整数;第二行输入n个整数。
Output
输出占一行。对这n个整数数按照从小到大的顺序输出,数据之间用一个空格隔开。
Sample Input
6
6 5 1 2 3 4
Sample Output
1 2 3 4 5 6
HINT
Source
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include<stdio.h> int main() { int a[10],i,j,t,m; scanf("%d",&m); for(i=0;i<m;i++) scanf("%d",&a[i]); for(j=0;j<m-1;j++) for(i=0;i<m-j-1;i++) if(a[i]>a[i+1]) { t=a[i]; a[i]=a[i+1]; a[i+1]=t; } for(i=0;i<m;i++){ if(i==m-1) printf("%d",a[i]); else printf("%d ",a[i]); } }
转载于:https://my.oschina.net/zhuzhiqiang/blog/671682
最后
以上就是忐忑铅笔最近收集整理的关于zzuli OJ 1119: 一维数组排序的全部内容,更多相关zzuli内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复