Advertisement
mohamed_wagdy12

Untitled

Apr 26th, 2018
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1.  
  2. /*
  3. University : HTI
  4. CodeName : Write a program to sort array ascending
  5. SubjectName : Programming Structure
  6. SubjectCode : csc121
  7. Group : https://www.facebook.com/groups/1421186571334814
  8. event : Ready to final
  9. */
  10.  
  11. #include "stdafx.h"
  12. #include "iostream"
  13.  
  14. using namespace std;
  15.  
  16. int main(void)
  17. {
  18.  
  19. int x[5], h;
  20.  
  21. // Insert [x] Array
  22. for(int i = 0; i < 5; i++)
  23. {
  24. cout << "X[" << (i+1) << "][" << (i+1) << "]= ";
  25. cin >> x[i];
  26.  
  27. }
  28.  
  29. // Sort the array
  30. for(int i = 0; i < 4; i++)
  31. {
  32. for(int n = i+1; n < 5; n++)
  33. {
  34. // if you want to sort it descending make x[i] < x[n]
  35. if(x[i] > x[n]){
  36. h = x[i];
  37. x[i] = x[n];
  38. x[n] = h;
  39. }
  40. }
  41. }
  42.  
  43. // print Array
  44. for(int i = 0; i < 5; i++)
  45. {
  46. cout << " " << x[i] << " ";
  47. }
  48.  
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement