Quick actions

cmd+k|ctrl+k

Navigation

Languages

lab7 (940)

Snippet info

Language

Cpp

Visibility

public

Author

andrusus.korotkovus

Created

2018-12-20T23:44:43Z

Updated

2018-12-20T23:44:43Z

#include <iostream>
#include <ctime>

using namespace std;

int main()
{
	int n;
	int suma=0, pro=0;
	cout << "enter quantity n" << endl;
	cin >> n;
	
	int **array = new int*[n];

	for (int i = 0; i < n; i++)
	{
		array[i] = new int[n];
	}
	//-------------------------------

	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++)
		{
			array[i][j] = rand() % 10;
		}
	}

	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++)
		{
			cout << array[i][j] << "  ";
		}
		cout << endl;
	}
	cout << endl;
	//-------------------------------
	int x, y;
	srand(time(NULL));
	x = rand() % n;
	y = rand() % n;
	cout <<"Random numbers"<< "\n" << x << "\t" << y << "\n";

	//суммa двух любых элементов главной диагонали массива
	suma += array[x][x] + array[y][y];
	
	//произведения двух любых элементов побочной диагонали массива
	pro += array[x][n - x - 1] * array[y][n - y - 1];
	
	cout << "Result 1 - " << suma;
	cout << endl << endl;
	cout << "Result 2 - " << pro;

	//-------------------------------
	for (int i = 0; i < n; i++)
	{
		delete[] array[i];
	}
	delete[] array;


	return 0;
}


INFO