Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class Matrix{
- double p[3][3];
- double q[3][3];
- double r[3][3];
- public:
- void mult(double p[3][3], double q[3][3]);
- void output();
- };
- void Matrix::mult(double p[3][3], double q[3][3])
- {
- int num = 0;
- int j = 0;
- for(int i = 0; i < 3; i++)
- {
- num = 0;
- for(j = 0; j < 3; j++)
- {
- if(num < 3)
- {
- r[num][i] += (p[j][i] * r[num][j]);
- if(j == 2)
- {
- num ++;
- j = 0;
- }
- }
- }
- }
- }
- void Matrix::output()
- {
- int i = 0;
- int j = 0;
- cout << "Results:\n";
- for(int i = 0; i < 3; i++)
- {
- for (int j = 0; j < 3; j++)
- {
- cout << r[i][j] << " ";
- }
- cout << "\n";
- }
- }
- int main()
- {
- double x[3][3];
- double y[3][3];
- Matrix answer;
- int i = 0;
- int j = 0;
- cout << "Enter values of the first Matrix left to right.\n";
- for(int i = 0; i < 3; i++)
- {
- for (int j = 0; j < 3; j++)
- {
- cin >> x[i][j];
- }
- }
- cout << "Enter values of the second Matrix left to right.\n";
- for(int i = 0; i < 3; i++)
- {
- for (int j = 0; j < 3; j++)
- {
- cin >> y[i][j];
- }
- }
- answer.mult(x, y);
- answer.output();
- int hold; //holds the Console open.
- cin >> hold;
- cin.ignore();
- }
Add Comment
Please, Sign In to add comment