Advertisement
Guest User

waawa

a guest
Jan 20th, 2019
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. 1. //Alano, Raphael D.
  2. 2. //IT-01
  3. 3.
  4. 4. #include<iostream>
  5. 5. using namespace std;
  6. 6. int main()
  7. 7. {
  8. 8. int num[5];
  9. 9. int total;
  10. 10. int x;
  11. 11. int temp;
  12. 12. float average;
  13. 13.
  14. 14. cout << "Input 5 random numbers."<<endl;
  15. 15. for(x=0;x<=4;x++)
  16. 16. {
  17. 17. cout << "No. [" << x+1 << "]"<<endl;
  18. 18. cin >> num[x];
  19. 19. total= total+num[x];
  20. 20. }
  21. 21. average=total/x;
  22. 22.
  23. 23. cout<<"The total is: " <<total<<endl;
  24. 24. cout<<"The average is: " <<average<<endl;
  25. 25.
  26. 26. for (x = 0; x <= 4; x++)
  27. 27. {
  28. 28. for (int i = x + 1; i <= 4; i++)
  29. 29. {
  30. 30. if (num[x] > num[i])
  31. 31. {
  32. 32. temp = num[x];
  33. 33. num[x] = num[i];
  34. 34. num[i] = temp;
  35. 35. }
  36. 36. }
  37. 37. }
  38. 38. cout<<"The minimum is: "<<num[0];
  39. 39. cout<<"The maximum is: "<<num[4];
  40. 40. cout<<"Ascending Order: ";
  41. 41.
  42. 42. for(x=0;x<5;x++)
  43. 43.
  44. 44. cout<<num[x] << " ";
  45. 45.
  46. 46. for (x = 0; x <= 4; x++)
  47. 47. {
  48. 48.
  49. 49. for (int i = x + 1; i <= 4; i++)
  50. 50. {
  51. 51.
  52. 52. if (num[x] < num[i])
  53. 53. {
  54. 54.
  55. 55. temp = num[x];
  56. 56. num[x] = num[i];
  57. 57. num[i] = temp;
  58. 58. }
  59. 59. }
  60. 60. }
  61. 61. cout<<"Descending Order: ";
  62. 62. for(x=0;x<5;x++)
  63. 63. cout << num[x] << " ";
  64. 64. system(“pause”);
  65. 65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement