Другие языки программирования и технологии

написать - пояснить код программы в С++

Заданы 2 квадратные матрицы. Вычислить произведение матриц и произвести транспонирование любой матрицы (либо исходной, либо итоговой) . Ввод, вывод и транспонирование провести отдельными функциями
#include <iostream>
#include <ctime>
using namespace std;

// прототипы функций
int **crte(int **a, int size); // создание матриц
int **scan(int **a, int size); // считывание значений матрицы
int **mlt(int **a, int **b, int **c, int size); // умнажение матриц
void transp(int **a, int size); // транспонирование матрицы
void disp(int **a, int size); // вывод матриц на экран
void del(int **a, int size); // удаление матрицы

int main(){
srand(time(0));

int N; // размеры матриц
int **ar = 0, **ar2 = 0, **mult = 0; // три динамические матрицы

cout << "Enter size of matrixs: ";
cin >> N;

ar = crte(ar,N);
ar2 = crte(ar2,N);
mult = crte(mult,N);

cout << "Enter values of first matrix: \n";
ar = scan(ar,N);
cout << "Enter values of second matrix: \n";
ar2 = scan(ar2,N);

mult = mlt(ar,ar2,mult,N);

disp(ar,N);
disp(ar2,N);
disp(mult,N);

transp(mult,N);
disp(mult,N);

del(ar,N);
del(ar2,N);
del(mult,N);

system("pause > nul");
return 0;
}

int **crte(int **a, int size)
{
a = new int*[size];

for(int i(0); i < size; i++)
a[i] = new int[size];

return a;
}

int **scan(int **a, int size)
{
//int c = 1, b = 20;

for(int i(0); i < size; i++)
for(int j(0); j < size; j++)
//a[i][j] = rand() % (b - c + 1) + c;
cin >> a[i][j];

return a;
}

void disp(int **a, int size)
{
for(int i(0); i < size; i++){
for(int j(0); j < size; j++){
cout.width(4);
cout << a[i][j];
}
cout << endl;
}
cout << endl;
}

int **mlt(int **a, int **b, int **c, int size)
{
for(int i(0); i < size; i++)
for(int j(0); j < size; j++)
c[i][j] = 0;

for(int i(0); i <size; i++)
for(int j(0); j < size; j++)
for(int k(0); k < size; k++)
c[i][j] += a[i][k] * b[k][j];

return c;
}

void transp(int **a, int size)
{
for(int i(0); i < size; i++)
for(int j(i); j < size; j++)
if(i != j){
int temp = a[i][j];
a[i][j] = a[j][i];
a[j][i] = temp;
}
}

void del(int **a, int size)
{
for(int i = 0; i < size; i++)
delete []a[i];
delete []a;
}
Виктор Михайленко
Виктор Михайленко
5 430
Лучший ответ
эмм. . .А что пояснить-то? Задание вполне корректно и не требует уточнений. Спрашивайте конкретнее, что в вашем коде вас не устраивает?
Batyr Kaiypov
Batyr Kaiypov
20 490
Вот накидал, ввод/вывод сделай сам как спец-задание тебе.
http://ideone.com/ZdnNMF