-
-
Save pereslavtsev/7805966 to your computer and use it in GitHub Desktop.
Программа Андрея на нахождение произведения матриц
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 312.cpp: определяет точку входа для консольного приложения. | |
// | |
#include "stdafx.h" | |
#include <iomanip> | |
#include <iostream> | |
using namespace std; | |
const int str=3; | |
const int stlb=3; | |
void zap_m(int **mas, const int str, const int stlb) | |
{ | |
for (int i = 0; i < str; i++) | |
for (int j = 0; j < stlb; j++) | |
mas[i][j] = rand() % 7 + 1; | |
} | |
void print_m(int **mas, const int str, const int stlb) | |
{ | |
for (int i = 0; i < str; i++) | |
{ | |
for (int j = 0; j < stlb; j++) | |
cout << setw(3) << mas[i][j]; | |
cout << endl; | |
} | |
} | |
void proizv_m(int **mas, int **mas2, int **mas3) | |
{ | |
for(int i = 0; i < stlb; i++) | |
{ | |
for (int j = 0; j < stlb; j++) | |
{ | |
mas3[i][j]=0; | |
for(int k = 1; k < stlb; k++) | |
{ | |
mas3[i][j] += mas[i][k] * mas2[k][j]; | |
} | |
} | |
} | |
cout<<endl; | |
} | |
int _tmain(int argc, _TCHAR* argv[]) | |
{ | |
setlocale(LC_ALL, "Rus"); | |
srand(time(0)); | |
int **mas = new int*[str]; | |
for (int i = 0; i < str; i++) | |
{ | |
mas[i] = new int[stlb]; | |
} | |
int **mas2 = new int*[str]; | |
for (int i = 0; i < str; i++) | |
{ | |
mas2[i] = new int[stlb]; | |
} | |
int **mas3 = new int*[str]; | |
for (int i = 0; i < str; i++) | |
{ | |
mas3[i] = new int[stlb]; | |
} | |
zap_m(mas, str, stlb); | |
print_m(mas, str, stlb); | |
cout<<endl; | |
zap_m(mas2, str, stlb); | |
print_m(mas2, str, stlb); | |
cout<<endl; | |
cout<<"Произведение: "<<endl; | |
proizv_m(mas, mas2, mas3); | |
print_m(mas3, str, stlb); | |
_sleep(99999); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment