Posted by : 86Gems 26 February 2014

 Sắp xếp mảng từ thấp đến cao


#include <iostream>
using namespace std;
void sx (int a[],int n)
{
    for (int i=0;i<n;i++)
    {
            for(int j=i;j<n;j++)
            {
                if(a[i] >a[j])
                    {
                        int tg = a[i];
                        a[i]=a[j];
                        a[j]=tg;
                    }
            }
    }
}

int main()
{
int m[100],n;
cout <<"Nhap n: ";
cin >> n;
cout << endl;
for (int j=0; j<n;j++)
{
    cout << "Nhap phan tu thu "<<j+1<<" : ";
    cin >> m[j];
}
sx(m,n);
cout << "Mang sau khi sap xep la: ";
for (int j=0; j<n;j++)
{
    cout << m[j] << ",  ";
}
return(0);
}

fb.com/snowblack93



Leave a Reply

Subscribe to Posts | Subscribe to Comments

- Copyright © Kiến thức tổng quan - Vòng Đá 5A - Powered by Blogger - Designed by SnowBlack -