Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <locale>
- #include <time.h>
- #include <iomanip>
- using namespace std;
- void Print(int** matr, int n, int m){ //Функция для печати матрицы
- int i = 0, j = 0;
- while (j < m){
- while (i < n){
- cout << setw(6) << matr[i][j] << " ";
- i++;
- }
- i = 0;
- cout << endl;
- j++;
- }
- }
- int* form_mas(int count){
- int* massive = new int[count];
- int a = 0;
- while (a < count){
- massive[a] = rand() % 50;
- a++;
- }
- return massive;
- }
- int** form_matr(int n, int m)
- {
- int **matr = new int*[n]; //выделение памяти под массив указателей
- for (int i = 0; i < n; i++){
- matr[i] = form_mas(m);
- }
- return matr;//возвращаем указатель на массив указателей
- }
- void delete_str(int** matr, int n, int m){
- // Удалить все четные столбцы
- int a = 0, i=0, j = 0,prost=0,b;
- int k = 1;
- int** matr_new = form_matr(n, m);
- while (j < m){
- while (i <= n-1){
- matr_new[i][j] = matr[k][j];
- i++;
- k += 2;
- }
- i = 0;
- k = 1;
- j++;
- }
- cout << endl;
- cout << "Матрица после обработки : " << endl;
- cout << endl;
- Print(matr_new, n, m);
- }
- void main()
- {
- int n, m, i = 0, j = 0;
- setlocale(LC_ALL, "rus");
- cout << "Введите кол-во столбцов в двумерном массиве" << endl;
- cin >> n;
- cout << "Введите кол-во строк в двумерном массиве" << endl;
- cin >> m;
- time_t t;
- srand((unsigned)time(&t));
- int** matr = form_matr(n, m);
- cout << "Исходная матрица : " << endl;
- Print(matr, n, m);
- delete_str(matr, n/2, m);
- }
Advertisement
Add Comment
Please, Sign In to add comment