Advertisement
Guest User

Untitled

a guest
Apr 1st, 2015
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <ctime>
  4. #include <cstdlib>
  5. #include <iomanip>
  6. #include <conio.h>
  7.  
  8. using namespace std;
  9.  
  10. int main(int argc, char* argv[])
  11. {
  12. setlocale(LC_ALL, "rus");
  13. int array[10][11];
  14. int max = 0;
  15. int number, counter;
  16. int key;
  17.  
  18. srand(time(NULL));
  19.  
  20. for (int i = 1; i < 10; i++)
  21. {
  22. for (int j = 0; j < 11; j++)
  23. {
  24. array[i][j] = rand() % 241 - 70;
  25. cout << setw(4) << array[i][j] << " ";
  26. }
  27. cout << endl;
  28. }
  29.  
  30. do {
  31. cout << "Для вывода максимального элемента массива введите 1" << endl;
  32. cout << "Для сортировки строки массива введите 2" << endl;
  33. cin >> counter;
  34.  
  35. switch (counter)
  36. {
  37. case 1:
  38. for (int i = 1; i < 10; i++)
  39. {
  40. for (int j = 0; j < 11; j++)
  41. if (array[i][j]>max) max = array[i][j];
  42. }
  43. cout << "Максимальный элемент массива равен " << max << endl;
  44. break;
  45. case 2:
  46. cout << "Введите номер строки для сортировки" << endl;
  47. cin >> number;
  48.  
  49. for (int i = 0; i < 11; i++)
  50. {
  51. int с = array[0][0];
  52. for (int j = i + 1; j < 11; j++)
  53. {
  54. if (array[number][i] > array[number][j])
  55. {
  56. с = array[number][i];
  57. array[number][i] = array[number][j];
  58. array[number][j] = с;
  59. }
  60. }
  61. }
  62. for (int i = 1; i < 10; i++)
  63. {
  64. for (int j = 0; j < 11; j++)
  65. cout << setw(4) << array[i][j] << " ";
  66. cout << endl;
  67. }
  68. break;
  69. default: cout << "Введено неверное значение" << endl;
  70. }
  71.  
  72. cout << endl << "Для продолжения нажмите Enter, или любую другую клавишу для выхода" << endl << endl;
  73. key = _getch();
  74.  
  75. } while (key == 13);
  76.  
  77. return(0);
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement