Skip to content

Instantly share code, notes, and snippets.

@rkhang7
Created December 23, 2018 02:59
Show Gist options
  • Save rkhang7/de2908b0e4dbc5fb37c33052b3d67f10 to your computer and use it in GitHub Desktop.
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.
#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