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_Matr(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 = 0;
- while (j < m){
- while (i < n){
- for (k = 2; (k < (matr[i][j]-1)) && (prost==0); k++){
- if (matr[i][j] % k == 0 ){
- prost = 1;
- }
- }
- if (prost == 0 && (abs(matr[i][j])>2)){
- for (a = j; a < m - 1; a++){
- for (b = 0; b < n; b++){
- matr[b][a] = matr[b][a + 1];
- }
- }
- j--;
- m--;
- }
- i++;
- prost = 0;
- }
- i = 0;
- j++;
- }
- cout << endl;
- cout << "Матрица после обработки : " << endl;
- cout << endl;
- Print_Matr(matr, 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(matr, n, m);
- delete_str(matr, n, m);
- }
Advertisement
Add Comment
Please, Sign In to add comment