Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<math.h>
- #include<string>
- #define MAX 1000
- using namespace std;
- void nhap(int a[],int &n)
- {
- do
- {
- cin>>n;
- }while(n < 0 || n > MAX);
- for(int i = 0; i < n; i++)
- {
- cin>>a[i];
- }
- }
- void xuat(int a[],int n)
- {
- for(int i = 0; i < n; i++)
- {
- cout<<a[i]<<"\t";
- }
- }
- void sapxep(int a[],int n)
- {
- for(int i = 0; i < n-1 ; i++)
- {
- if(a[i] % 2 != 0)
- {
- for(int j = i + 1; j < n;j++)
- {
- int k;
- if(a[i] > a[j])
- {
- k = a[i];
- a[i] = a[j];
- a[j] = k;
- }
- }
- }
- }
- }
- int main()
- {
- int n;
- int a[MAX];
- nhap(a,n);
- sapxep(a,n);
- xuat(a,n);
- return 0;
- }
Add Comment
Please, Sign In to add comment