Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <stdio.h>
- using namespace std;
- void print(int A[][7], int D[][5], int N, int M)
- {
- cout << "Matrix A:" << endl;
- for (int i = 0;i < N;i++)
- {
- for (int j = 0;j < M;j++)
- {
- cout << A[i][j] << "\t";
- }
- cout << endl;
- }
- cout << "Matrix D: " << endl;
- for (int i = 0;i < M;i++)
- {
- for (int j = 0;j < N;j++)
- {
- cout << D[i][j] << "\t";
- }
- cout << endl;
- }
- }
- void print2(int c[][5], int N)
- {
- for (int i = 0; i < N; i++)
- {
- for (int j = 0; j < N; j++)
- {
- cout << c[i][j] << "\t";
- }
- cout << endl;
- }
- }
- void pr_matrix(int A[][7],int c[][5], int D[][5],const int N, int M)
- {
- for (int i = 0; i < N; i++)
- {
- for (int j = 0; j < N; j++)
- {
- for (int k = 0; k < M; k++)
- {
- c[i][j] += A[i][k] * D[k][j];
- }
- }
- }
- print2(c, N);
- }
- int main()
- {
- ifstream file1("C:\\Users\\Irinda\\source\\repos\\Задание 1\\text1.txt");
- ifstream file("C:\\Users\\Irinda\\source\\repos\\Задание 1\\text.txt");
- if (!file)
- {
- cout << "File is not open";
- return -1;
- }
- else
- {
- cout << "File is open" << endl;
- const int N = 5;
- const int M = 7;
- int A[N][M];
- int D[M][N];
- int c[N][N];
- for (int i = 0;i < N;i++)
- {
- for (int j = 0;j < M;j++)
- {
- if (!file.eof())
- {
- file >> A[i][j];
- }
- }
- }
- for (int i = 0;i < M;i++)
- {
- for (int j = 0;j < N;j++)
- {
- if (!file1.eof())
- {
- file1 >> D[i][j];
- }
- }
- }
- for (int i = 0; i < N; i++)
- {
- for (int j = 0; j < N; j++)
- {
- c[i][j] = 0;
- }
- }
- print(A, D, N, M);
- cout << endl;
- cout << "Matrix comsposition:" << endl;
- pr_matrix(A,c, D, N, M);
- file.close();
- system("pause");
- return 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement