Created
December 23, 2018 02:59
-
-
Save rkhang7/de2908b0e4dbc5fb37c33052b3d67f10 to your computer and use it in GitHub Desktop.
Sử dụng lại bài 29. Viết chương trình sắp xếp tăng dần các phần tử trong mảng 1 chiều.
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
#include <stdio.h> | |
#include <conio.h> | |
void doivt(int &a,int &b) | |
{ | |
int c; | |
c=a; | |
a=b; | |
b=c; | |
} | |
void xuatmang(int a[], int n) | |
{ | |
for(int i = 0;i < n;i++) | |
printf("%d\t", a[i]); | |
} | |
int main() | |
{ | |
int n; | |
printf("Nhap so phan tu cua mang: ");scanf("%d", &n); | |
int a[n]; | |
for(int i = 0;i < n;i++) | |
{ | |
printf("a[%d]=",i);scanf("%d", &a[i]); | |
} | |
printf("Mang sau khi sap xep la: "); | |
for(int i = 0; i < n ;i++){ | |
for(int j = n-1; j > i; j--) | |
if(a[i] > a[j]) doivt(a[i],a[j]); | |
} | |
xuatmang(a,n); | |
getch(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment