answer (В двумерном массиве поменять местами строки)

#include "stdafx.h"//del #include <iostream> #include <iomanip> using namespace std; int main() { const int N = 3;//квадратная матрица N x N //создание int **pMas = new int*[N]; //строки for (int i = 0; i < N; i++) pMas[i] = new int[N]; //столбцы //заполнение for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) pMas[i][j] = (rand() % 10 + 1) / (rand() % 10 + 1); //вывод for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { cout << setw(4) << pMas[i][j]; } cout << endl; } //изменение, поменяем местами первую и третью строку int *pTmp = new int[N]; pTmp = pMas[0]; pMas[0] = pMas[2]; pMas[2] = pTmp; //вывод cout << endl; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { cout << setw(4) << pMas[i][j]; } cout << endl; } \ for (int i = 0; i < N; i++) delete[] pMas[i]; delete[] pMas; return 0; }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.