-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMooc-7-2.c
64 lines (64 loc) · 1.44 KB
/
Mooc-7-2.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
////题目内容:
////
////从键盘输入n个(n≤10)整数,用交换法进行排序(非递减有序),结果输出排序后的序列。说明:交换法排序用函数实现,函数原型为:void sort(int* a, int n); 交换法排序的基本思想是:n个元素共需要n - 1趟,其中第i(从0变化至n - 2)趟的任务是找出本趟中最小的元素放在下标为i的位置上,每趟通过从i + 1到n - 1下标的元素逐个与i下标元素比较及时交换进行排序。
////
////
////
////输入格式:
////
////先输入n的值,再用循环输入n个数组元素,输入每个整数用的格式控制串都是"%d"
////
////说明:输入n时假定输入的值一定在闭区间[1, 10]之内,不需要用分支或循环结构对输入n的值再进行判断。
////
////
////
////输出格式:
////
////输出交换后的序列,单个元素输出时printf中使用的格式串为"%d " (请在程序中直接复制这个格式串)
////
////所有元素输出结束后用printf("\n"); 进行换行处理。
////
////
////
////输入样例:
////
////9
////
////5 6 3 8 23 90 12 34 25
////
////
////
////输出样例:
////
////3 5 6 8 12 23 25 34 90
//
//
//
//#include<stdio.h>
//void sort(int *p, int n);
//int main() {
// int n, a[10];
// scanf("%d", &n);
// for (int i = 0; i < n; i++) {
// scanf("%d", a[i]);
// }
// sort(a,n);
// for (int i = 0; i < n; i++) {
// printf("%d ", a[i]);
// }
// printf("\n");
// return 0;
//}
// void sort(int *p,int n) {
// int i, j, t;
// for (i = 0; i < n - 2; i++) {
// for (j = i + 1; j < n; j++) {
// if (p[i] > p[j]) {
// t = p [i];
// p [i] = p [j];
// p [j] = t;
// }
// }
// }
//}
//