Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <time.h>
- #include <conio.h>
- using namespace std;
- 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;
- }
- void prog(int** matrix, int Rows, int Collums)
- {
- int temp1,temp2;
- int count = 0;
- int t = Rows -1 ;
- for (int j = 0; j < Collums; j++)
- {
- for (int i = 0; i < Rows; i++)
- {
- if (matrix[i][j] %3==0)
- count++;//подсчет числа кратным 3
- }
- temp1 = matrix[t][j];
- for (int k = t; k < Rows; k++)
- {
- temp2 = matrix[k + 1][j];
- matrix[k + 1][j] = temp1;
- temp1 = temp2;
- }
- matrix[t][j] = count;
- t--;
- count = 0;
- }
- }
- 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+1]; //массив указателей
- for (int i = 0; i < Rows+1; i++)
- {
- matrix[i] = new int[Collums]; // Создаем элементы
- }
- generation(matrix, Rows, Collums);
- printmatrix(matrix, Rows, Collums);
- prog(matrix, Rows, Collums);
- cout << "New matrix. On optional diagonal elements multiple 3"<< endl;
- for (int i = 0; i < Rows+1; i++)
- {
- for (int j = 0; j < Collums; j++)
- {
- cout.width(10);
- cout << *(*(matrix + i) + j);
- }
- cout << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement