Untitled
unknown
plain_text
4 months ago
2.0 kB
5
Indexable
#include <iostream> #include <cstdlib> #include <ctime> #include <clocale> const int N = 6; void generateMatrix(int matrix[N][N]) { for (int i = 0; i < N; ++i) for (int j = 0; j < N; ++j) matrix[i][j] = rand() % 100; } void printMatrix(const int matrix[N][N]) { for (int i = 0; i < N; ++i) { for (int j = 0; j < N; ++j) std::cout << matrix[i][j] << "\t"; std::cout << std::endl; } } void analyzeMatrix(const int matrix[N][N], int& minValue, int& maxValue) { minValue = matrix[N / 2][0]; maxValue = matrix[N / 2][0]; for (int i = N / 2; i < N; ++i) { for (int j = 0; j < N; ++j) { if (matrix[i][j] < minValue) minValue = matrix[i][j]; if (matrix[i][j] > maxValue) maxValue = matrix[i][j]; } } } void displayMenu() { std::cout << "menu:\n1. generate matrix\n2. analize matrix\n3. exit\n"; } int main() { setlocale(LC_ALL, "RU"); srand(int(time(0))); int matrix[N][N], minValue, maxValue, choice; while (true) { displayMenu(); std::cout << "enter the action number: "; std::cin >> choice; if (choice == 1) { generateMatrix(matrix); std::cout << "generated matrix:\n"; printMatrix(matrix); } else if (choice == 2) { analyzeMatrix(matrix, minValue, maxValue); std::cout << "minimum value in the shaded area: " << minValue << std::endl; std::cout << "maximum value in the shaded area: " << maxValue << std::endl; } else if (choice == 3) { std::cout << "exiting the program.\n"; break; } else { std::cout << "incorrect input. please try again..\n"; } } return 0; }
Editor is loading...
Leave a Comment