//Tran Van Hien 15T3
#include <iostream>
using namespace std;
void Nhap(double *pa, int n){
for (int i=0;i<n;i++){
cout<<"Nhap a["<<i<<"]=";
cin>>*pa;
pa++;
}
}
void HoanVi(double *x, double *y){
double temp = *x;
*x = *y;
*y= temp;
}
void SapXep(double *pa, int n){
for(int i=0; i<n; i++)
for(int j = i+1; j<n; j++){
if ( *(pa+i) > *(pa+j)) HoanVi(pa+i,pa+j);
}
}
int main(){
int n;
cout<<"Nhap so luong phan tu: "<<endl;
cin>>n;
double a[n];
Nhap(&a[0],n);
for(int i=0; i<n;i++){
cout<<a[i]<<" ";
};
SapXep(&a[0],n); cout<<endl;
for(int i=0; i<n;i++){
cout<<a[i]<<" ";
};
return 1;
}
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.