Guest User

Untitled

a guest
Jun 24th, 2018
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. //Array-01
  2. #include <iostream>
  3. using namespace std;
  4. main()
  5. {
  6. int a[5],i;
  7. for (i=0; i<5; i++)
  8.  
  9. {
  10. cout<<"nhap so "<< "\t" ;
  11. cin >> a[i];
  12. }
  13. cout << "Nhap cac phan tu cua mang: " << endl;
  14. for (i=0; i<5; i++)
  15.  
  16. {
  17. cout << a[i] << endl;
  18. }
  19.  
  20. int b=a[0];
  21. for (int i=0; i<5; i++)
  22. {
  23. if(b<a[i])
  24. {
  25. b=a[i];
  26. }
  27. }
  28. cout << "MAX"<< b<< endl;
  29. int c=a[0];
  30. for (int i=0; i<5;i++)
  31. {
  32. if (c>a[i])
  33. {
  34. c=a[i];
  35. }
  36. }
  37. cout << "MIN"<< c <<endl;
  38. int temp;
  39. for (i=0;i<5;i++)
  40. {
  41. for (int j=i+1; j<5; j++)
  42. {
  43. if (a[i]>a[j])
  44. {
  45. temp=a[i];
  46. a[i]=a[j];
  47. a[j]=temp;
  48. }
  49. }
  50. }
  51. cout << "sap xep tu nho den lon:" << endl;
  52. for (int i = 0; i<5 ; i++)
  53. {
  54. cout << a[i] <<endl;
  55. }
  56. for (i =0 ; i < 5 ; i++)
  57. {
  58. for (int j = i + 1 ; j <5 ; j++)
  59. {
  60. if (a[i] < a[j]);
  61. {
  62. temp = a[j];
  63. a[j] = a[i];
  64. a[i] = temp;
  65. }
  66. }
  67. }
  68. cout << "sap xep tu lon den be: " << endl;
  69. for ( i = 0; i < 5; i++)
  70. {
  71. cout << a[i] << endl ;
  72. }
  73. }
Add Comment
Please, Sign In to add comment