Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <clocale>
- int** createMatrix(int N);
- void fullMatrix(int** M, int N);
- void printMatrix(int** M, int N);
- void printSumPlusColumn(int** M, int N);
- int main()
- {
- setlocale(0, "");
- /*const int N = 6;*/
- int N = 0;
- std::cout << "Введи размер матрицы:)" << std::endl;
- std::cin >> N;
- int** A = createMatrix(N);
- fullMatrix(A, N);
- printMatrix(A, N);
- printSumPlusColumn(A, N);
- delete[] A;
- system("pause");
- return 0;
- }
- int** createMatrix(const int N){
- int** M = new int* [N];
- for (int i = 0; i < N; i++)
- {
- M[i] = new int[N];
- }
- return M;
- }
- void fullMatrix(int** M, const int N){
- for (int i = 0; i < N; i++)
- {
- for (int j = 0; j < N; j++)
- {
- M[i][j] = -5+rand() % 10;
- }
- }
- }
- void printMatrix(int** M, const int N){
- std::cout << "Матрица:" << std::endl;
- std::cout << "-----------------------" << std::endl;
- for (int i = 0; i < N; i++)
- {
- for (int j = 0; j < N; j++)
- {
- std::cout << M[i][j] << '\t';
- }
- std::cout << std::endl;
- }
- }
- void printSumPlusColumn(int **matrix, const int N){
- std::cout << "Сумма положительных чисел в каждом столбце:" << std::endl;
- std::cout << "-----------------------" << std::endl;
- int sum;
- for (int i = 0; i < N; ++i)
- {
- sum = 0;
- for (int j = 0; j < N; ++j) {
- if (matrix[j][i] > 0)
- sum += matrix[j][i];
- }
- std::cout << sum << '\t';
- }
- std::cout << std::endl << "-----------------------" << std::endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment