Top.Mail.Ru
Ответы

Помогите разобраться в программе на с++

дана программа на С++
разобраться, что делает каждая строчка

#include
#include
#include
#include
#include

using namespace std;

void setColorAttr(int attr)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), attr);
}

int main(int argc, char **argv)
{
int **matrix = NULL;
int m, n, sum = 0;

srand((unsigned)time(NULL));
setColorAttr(2 + (0 << 4));

cout << "input n: ";
cin >> n;

matrix = new int *[n];
for (size_t i = 0; i < n; i++)
matrix[i] = new int[n];

for (size_t j = 0; j < n; j++)
{
for (size_t i = 0; i < n; i++)
{
setColorAttr(2 + (0 << 4));
if (i == j)
setColorAttr(0 + (2 << 4));

cout << setw(3) << (matrix[j][i] = rand() % 100);
}

sum += matrix[j][j];
cout << endl;
}

setColorAttr(2 + (0 << 4));
cout << "\nSum = " << sum << endl;

for (size_t i = 0; i < n; i++)
delete[] matrix[i];

delete[] matrix;

system("pause");
return 0;
}

По дате
По рейтингу
Аватар пользователя
Профи
10лет

Так это не программа это скрипт для компилятора