Advertisement
parad0xxxxx

LW6 andr

Jan 24th, 2020
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.20 KB | None | 0 0
  1. #include <iostream>
  2. #include <time.h>
  3. #include <iomanip>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. int arrayIndexSize, arraySize, randRangeFrom, randRangeTo, comparisonNumber;
  9. char v(0);
  10.  
  11. cout << "Enter array\'s first index\' value: ";
  12. cin >> arrayIndexSize;
  13.  
  14. cout << "Enter array\'s second index\' value: ";
  15. cin >> arraySize;
  16.  
  17. cout << "Enter number to compare: ";
  18. cin >> comparisonNumber;
  19.  
  20. if (arrayIndexSize < 1 || arraySize < 1) {
  21. cout << "\n\nBoth values must be posivive integers.\n\n";
  22. return 0;
  23. }
  24.  
  25. int** arr = new int* [arrayIndexSize];
  26.  
  27. for (int i = 0; i < arrayIndexSize; i++)
  28. {
  29. arr[i] = new int[arraySize];
  30. }
  31.  
  32. cout << "\n\nHow would You like to fill in array, (M)anually or (A)utomatically? \n:";
  33. cin >> v;
  34.  
  35. if (v == 'M') {
  36.  
  37. for (int i = 0; i < arrayIndexSize; i++)
  38. {
  39. cout << "Entering row " << i + 1 << ".\n\n";
  40. for (int j = 0; j < arraySize; j++)
  41. {
  42. cout << "Enter element " << j + 1 << ": ";
  43. cin >> arr[i][j];
  44.  
  45. }
  46. cout << endl;
  47. }
  48. }
  49.  
  50. else if (v == 'A') {
  51.  
  52. cout << "Enter initial range value: ";
  53. cin >> randRangeFrom;
  54.  
  55. cout << "Enter end range value: ";
  56. cin >> randRangeTo;
  57. cout << endl;
  58.  
  59. srand(time(NULL));
  60. for (int i = 0; i < arrayIndexSize; i++)
  61. {
  62. for (int j = 0; j < arraySize; j++)
  63. {
  64. arr[i][j] = rand() % (randRangeTo - randRangeFrom + 1) + randRangeFrom;
  65. }
  66. }
  67. }
  68.  
  69. else {
  70. cout << "\nI expected \"M\" or \"A\".\n";
  71. return 0;
  72. }
  73.  
  74. cout << "\n\n";
  75.  
  76. for (int i = 0; i < arrayIndexSize; i++)
  77. {
  78. for (int j = 0; j < arraySize; j++)
  79. {
  80. cout << setw(6) << arr[i][j];
  81. }
  82. cout << endl;
  83. }
  84. cout << endl;
  85.  
  86.  
  87. float sum = 0;
  88. float average;
  89. int amountCols = 0;
  90. for (int j = 0; j < arraySize; j++)
  91. {
  92. sum = 0;
  93. for (int i = 0; i < arrayIndexSize; i++)
  94. {
  95.  
  96. sum += arr[i][j];
  97.  
  98. }
  99. average = sum / arrayIndexSize;
  100. cout << setw(6) << average;
  101. if (average >= comparisonNumber) {
  102. amountCols++;
  103. }
  104. }
  105.  
  106. if (amountCols > 0)
  107. {
  108. cout << "\nAmount of columns: " << amountCols << endl;
  109. }
  110. else
  111. {
  112. cout << "\nNot found" << endl;
  113. }
  114.  
  115. for (int i = 0; i < arrayIndexSize; i++)
  116. {
  117. delete[] arr[i];
  118. }
  119.  
  120. delete[] arr;
  121.  
  122. return 0;
  123. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement