Quick actions

cmd+k|ctrl+k

Navigation

Languages

1467

Snippet info

Language

Cpp

Visibility

public

Author

nxnxngh

Created

2018-11-28T22:25:14Z

Updated

2018-12-08T15:25:25Z

#include <iostream>
#include<ctime>

using namespace std;

int main()
{
	srand(time(NULL));
	setlocale(LC_ALL, "ru");
	//Creation
	int row = 1 + rand()%6;
	int cols = 2*(1 + rand() % 3 );
	int **mass = new int* [row];
	for (int i = 0; i < row; i++)
	{
		mass[i] = new int[cols];
	}
	
	//Generating element value and show all af this elements
	cout<<"Default array elements:"<<endl;
	for (int i = 0; i < row; i++)
	{
		for (int j = 0; j < cols; j++)
		{
			mass[i][j] = rand()%20;
			cout << mass[i][j] << "\t";
		}
		cout << endl;
	}
    //Creating of second array
    int **arr = new int* [row];
	for (int i = 0; i < row; i++)
	{
		arr[i] = new int[cols];
	}
    //Reverse Copy
     int g;
    	for (int i = 0; i < row; i++)
	{
		for (int j = 0; j < (cols/2); j++)
		{
		    g = cols - j -1;
			arr[i][j] = mass[i][g];
		}
	}
    //Copy 
    	for (int i = 0; i < row; i++)
	{
		for (int j = 0; j < (cols); j++)
		{
		     g = cols - j -1;
			arr[i][g] = mass[i][j];
		}
	}
	//Changing all element of mass to elemnetst of arr
	   	for (int i = 0; i < row; i++)
	{
		for (int j = 0; j < (cols); j++)
		{
			mass[i][j]=arr[i][j];
		}
	}
		//Deleting second array
	for (int i = 0; i < row; i++)
	{
		delete[] arr[i];
	}
	delete[] arr;
	//underscores(Just for aesthetics)
	if((cols*8)<27)
	{
	    for(int i=0;i<35; i++)
    	{
    	cout<<"_";
    	}
	}
	else
	{
    	for(int i=0;i<(cols * 8); i++)
    	{
    	cout<<"_";
    	}
    }
	cout<<endl;
	//Show all elements of reversed array
	cout<<endl<<"Elements of reversed array:"<<endl;
	for (int i = 0; i < row; i++)
	{
		for (int j = 0; j < cols; j++)
		{
			cout << mass[i][j] << "\t";
		}
		cout << endl;
	}
	//Deleting
	for (int i = 0; i < row; i++)
	{
		delete[] mass[i];
	}
	delete[] mass;
	system("PAUSE");
	return 0;
}
INFO