Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // laba14.cpp : Этот файл содержит функцию "main". Здесь начинается и заканчивается выполнение программы.
- //
- #include <iostream>
- #include <stdio.h>
- #include <time.h>
- #include <conio.h>
- #include <string.h>
- using namespace std;
- void functionmass(int** matrix,int Rows, int Collums )
- {
- int count = 0;
- for (int j = 0; j < Rows; j++)
- {
- for (int i = 0; i < Collums; i++)
- {
- if (matrix[j][i] % 5 == 0)
- {
- count++;
- }
- }
- matrix[j][j] = count;
- count = 0;
- }
- }
- void function(int** matrix,int Collums, int num)
- {
- num -= 1;
- int count = 0;
- for (int i=0; i< Collums; i++)
- {
- if (matrix[num][i] % 5 == 0)
- {
- count++;
- }
- }
- matrix[num][num] = count;
- }
- void printmatrix(int** matrix, int Rows, int Collums)
- {
- for (int i = 0; i < Rows; i++)
- {
- for (int j = 0; j < Collums; j++)
- {
- cout.width(10);
- cout << *(*(matrix + i) + j);
- }
- cout << endl;
- }
- }
- void generation(int** matrix, int Rows, int Collums)
- {
- for (int i = 0; i < Rows; i++)
- {
- for (int j = 0; j < Collums; j++)
- {
- cout.width(10);
- *(*(matrix + i) + j) = rand() % 21 - 10;
- }
- }
- }
- void deletematrix(int** matrix, int Rows, int Collums)
- {
- for (int i = 0; i < Rows; i++)
- delete[] matrix[i];
- delete[]matrix;
- }
- int main()
- {
- srand(time(NULL));
- int Rows, Collums;
- cout << "Enter number of rows" << endl;
- cin >> Rows;
- cout << "Enter number of collums" << endl;
- cin >> Collums;
- int** matrix= new int*[Rows]; //массив указателей
- for (int i = 0; i < Rows; i++)
- {
- matrix[i] = new int[Collums]; // Создаем элементы
- }
- generation(matrix, Rows, Collums);
- printmatrix(matrix, Rows, Collums);
- int num=0;
- cout << "choose row or tap 0 for massfunction" << endl;
- scanf_s("%d", &num);
- if (num!=0)
- {
- function(matrix, Collums, num);
- cout << "New matrix" << endl;
- printmatrix(matrix, Rows, Collums);
- }
- else
- {
- cout << "function to all rows" << endl;
- functionmass(matrix, Rows,Collums);
- printmatrix(matrix, Rows, Collums);
- }
- cout << "matrix deleted" << endl;
- deletematrix(matrix, Rows, Collums);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement