Created
July 1, 2015 16:06
-
-
Save chingovan/a63680e09ec770731926 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* bubble_sort1.c | |
* | |
* Created on: Jul 1, 2015 | |
* Author: chinv | |
*/ | |
#include "stdio.h" | |
#define N 100 | |
void printArray(int a[], int n) { | |
int i; | |
for (i = 0; i < n; i++) { | |
printf("%d \t", a[i]); | |
} | |
} | |
int main(int argc, char **argv) { | |
int n; | |
int a[N]; | |
int i, j; | |
printf("Nhap vao so phan tu: "); | |
scanf("%d", &n); | |
printf("Nhap cac phan tu cua mang\n"); | |
for (i = 0; i < n; ++i) { | |
printf("a[%d] = ", (i + 1)); | |
scanf("%d", &a[i]); | |
} | |
printf("Mang vua nhap la: "); | |
printArray(a, n); | |
for (j = 0; j < n; j++) { | |
for (i = n - 1; i > 0; i--) { | |
if (a[i] < a[i - 1]) { | |
int t = a[i]; | |
a[i] = a[i - 1]; | |
a[i - 1] = t; | |
} | |
} | |
} | |
printf("Mang sau khi thuc hien thuat toan: "); | |
printArray(a, n); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment