Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- static void print(int *a, int n) {
- for (int i = 0; i < n; ++i) { printf("%s%d", (i == 0 ? "" : " "), a[i]); }
- puts("");
- }
- static void sort(int *a, int n) {
- for (int i = 0; i < n; ++i) {
- for (int j = i + 1, t; j < n; ++j) {
- if (a[j] < a[i]) { t = a[i], a[i] = a[j], a[j] = t; }
- printf("i = %d\tj = %d\t", i, j), print(a, n);
- }
- }
- }
- int main(void) {
- int a[] = {7, 4, 1, 3, 5, 2};
- int n = sizeof(a) / sizeof(a[0]);
- print(a, n), puts(""), sort(a, n);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement