Guest User

Untitled

a guest
Dec 14th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. #include<iostream>
  2. #include<math.h>
  3. #include<string>
  4.  
  5. #define MAX 1000
  6. using namespace std;
  7.  
  8. void nhap(int a[],int &n)
  9. {
  10. do
  11. {
  12. cin>>n;
  13. }while(n < 0 || n > MAX);
  14. for(int i = 0; i < n; i++)
  15. {
  16. cin>>a[i];
  17. }
  18. }
  19. void xuat(int a[],int n)
  20. {
  21. for(int i = 0; i < n; i++)
  22. {
  23. cout<<a[i]<<"\t";
  24. }
  25. }
  26. void sapxep(int a[],int n)
  27. {
  28. for(int i = 0; i < n-1 ; i++)
  29. {
  30. if(a[i] % 2 != 0)
  31. {
  32.  
  33. for(int j = i + 1; j < n;j++)
  34. {
  35. int k;
  36. if(a[i] > a[j])
  37. {
  38. k = a[i];
  39. a[i] = a[j];
  40. a[j] = k;
  41. }
  42. }
  43. }
  44. }
  45. }
  46.  
  47. int main()
  48. {
  49. int n;
  50. int a[MAX];
  51. nhap(a,n);
  52. sapxep(a,n);
  53. xuat(a,n);
  54. return 0;
  55. }
Add Comment
Please, Sign In to add comment