Advertisement
Guest User

Untitled

a guest
Dec 7th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. // ConsoleApplication 3.2(B).cpp: определяет точку входа для консольного приложения.
  2. //
  3. #include "stdafx.h"
  4. #include <iomanip>
  5. #include <stdlib.h>
  6. #include <iostream>
  7. #define size 5
  8.  
  9. using namespace std;
  10.  
  11. void Random(int a[size][size]);
  12. void View(int a[size][size]);
  13. int Max(int arr[size][size]);
  14. void New(int arr[size][size], int max);
  15.  
  16. int main()
  17.  
  18. {
  19. int i = 0, j = 0, g, k, c = 0;
  20. int a[size][size], b[size][size];
  21.  
  22. Random(a);
  23. View(a);
  24. New(b, Max(a));
  25. View(b);
  26.  
  27. system("pause");
  28. return 0;
  29.  
  30. }
  31.  
  32. void Random(int a[size][size])
  33. {
  34. int i, j, m, n;
  35. do
  36. {
  37. cout << "enter m and n:\n";
  38. cin >> m >> n;
  39. } while (m >= n);
  40.  
  41.  
  42. srand(time(NULL));
  43.  
  44. for (i = 0; i < size; i++)
  45. {
  46. for (j = 0; j < size; j++)
  47. {
  48. a[i][j] = rand() % (n - m + 1) + m;
  49. }
  50. }
  51. }
  52.  
  53. void View(int a[size][size])
  54. {
  55. int i, j;
  56.  
  57. for (i = 0; i < size; i++)
  58. {
  59. for (j = 0; j < size; j++)
  60. {
  61. cout << setw(3) << a[i][j];
  62. }
  63. cout << endl;
  64. }
  65. }
  66.  
  67. int Max(int arr[size][size])
  68. {
  69. int arr_max = arr[0][0];
  70. for (int i = 0; i < 3; i++)
  71. {
  72. for (int j = 0; j < 3; j++)
  73. {
  74. if (arr[i][j] > arr_max)
  75. {
  76. arr_max = arr[i][j];
  77. }
  78. }
  79.  
  80. cout << endl;
  81. }
  82.  
  83. return arr_max;
  84.  
  85. }
  86.  
  87. void New(int arr[size][size], int max)
  88. {
  89. for (int i = 0; i < size; i++)
  90. {
  91. for (int j = 0; j < size; j++)
  92. {
  93. arr[i][j] = max;
  94. }
  95.  
  96. cout << endl;
  97. }
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement