1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
|
#include <iostream>
using namespace std;
#include <cstdlib>
void fn(int **arr) {
}
void fn2 (int **arr2){
}
void fn3 (int **arr3){
}
int main() {
int r, c ,r2 , c2 , r3 , c3 , m , l;
cout << "Enter size of row 1 : " ;
cin >> r ;
cout << "Enter size of column 1 : " ;
cin >> c ;
cout <<"Enter matrix 1 please " ;
int **arr = new int*[r];
for (int i = 0; i < r; i++)
arr[i] = new int[c];
for (int i=0 ; i<r ; i++){
for (int j=0 ; j<c ; j++)
cin >> arr[i][j] ;
}
for (int i=0 ; i<r ; i++){
for (int j=0 ; j<c ; j++)
cout << arr[i][j]<<" " ;
cout << endl ;
}
cout << "Enter size of row 2 : " ;
cin >> r2 ;
cout << "Enter size of column2 : " ;
cin >> c2 ;
cout << "Enter matrix 2 please " ;
int **arr2 = new int*[r2];
for (int i = 0; i < r2 ; i++)
arr2[i] = new int[c2];
for (int i=0 ; i<r2 ; i++){
for (int j=0 ; j<c2 ; j++)
cin >> arr2[i][j] ;
}
for (int i=0 ; i<r2 ; i++){
for (int j=0 ; j<c2 ; j++)
cout << arr2[i][j] <<" " ;
cout << endl ;
}
int **arr3 ;
arr3 = new int * [r2];
for(int i=0;i<c;i++)
{
arr2[i] = new int [c2];
arr3[i] = new int [c2];
}
if (c != r2)
cout << "We cannot solve multiplication " ;
else {
for (int i = 0; i < r ; i++){
for (int j=0 ; j<c ; j++){
arr3[i][j]=0;
for (int k=0 ; k<2 ; k++){
arr3[i][j]=0;
arr3[i][j]=arr3[i][j]+(arr[i][k] * arr2[k][j]);
}
}
}
cout<<"your matrix is"<<endl;
for(int i=0;i<c;i++){
for(int j=0;j<r2;j++)
cout<<arr3[i][j]<<" ";
cout<<endl;
}
}
fn(arr);
fn2(arr2);
fn3(arr3);
return 0;
}
|
That is my final code is it right ???
please i need one tell me what i need to do as my teacher asks me to
Students MUST use functions
This is the whole question
Write a program that asks the user for two matrices: matrix A with dimensions LxM, and matrix B with dimensions MxN. The program then prints the matrix C of their multiplication with dimensions LxN. You MUST represent every matrix with a two-dimensional array. The program should ask the user to:
a) Enter the dimensions of the first matrix
b) Enter the dimensions of the second matrix
c) Enter the first matrix.
d) Enter the second matrix
After step b), the program should validate if the entered dimensions are valid for matrix multiplication. If invalid dimensions are entered, the program should print an error message, and ask the user again for new valid dimensions. After step d), the program prints the result matrix
sorry for being boring for somebody here !!!