Advertisement
Guest User

Untitled

a guest
Nov 15th, 2019
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1.  
  2. #include <iostream>
  3. using namespace std;
  4. int main()
  5. {
  6. setlocale(LC_ALL,"rus");
  7. const int MAX = 100;
  8. int num;
  9. int arr[MAX], temp[MAX];
  10. cout << "Введите размер массива (размер должен быть не больше" << MAX << "): ";
  11. cin >> num;
  12. for (int i=0; i<num; i++)
  13. {
  14. cout << "Введите " << i+1 << " элемент массива: ";
  15. cin >> arr[i];
  16. temp[i] = arr[i];
  17. }
  18.  
  19. for (int i=0; i< num; i++)
  20. {
  21. for (int j=0; j<num; j++ )
  22. {
  23. int buf;
  24. if (temp[j] < temp[j+1])
  25. {
  26. buf = temp[j];
  27. temp[j] = temp[j+1];
  28. temp[j+1]=buf;
  29. }
  30. }
  31.  
  32. }
  33.  
  34. cout << endl;
  35. for (int i=0; i<num; i++)
  36. {
  37. cout << arr[i] << " ";
  38. }
  39. cout << endl;
  40.  
  41. int count = 0;
  42. int tret = 0;
  43. for (int i=num; i>0; i--)
  44. {
  45. if (temp[i-1] != temp[i])
  46. {
  47. count++;
  48. if (count == 3)
  49. tret = temp[i-1];
  50. }
  51. }
  52. if (tret != 0)
  53. {
  54. cout << "3-е по величине число: " << tret << endl;
  55. cout << endl << "Преобразованный массив: "<< endl;
  56. for (int i=0; i<num; i++)
  57. {
  58. if (arr[i] > tret)
  59. arr[i] = tret;
  60. cout << arr[i] << " ";
  61. }
  62. cout << endl;
  63. }
  64. else
  65. {
  66. cout << "В данном массиве присутствует только два числа! Введите заново" << endl;
  67. }
  68.  
  69. return 0;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement