please help, the answers should be given im matlab code will rate Instructions:
ID: 3195144 • Letter: P
Question
please help, the answers should be given im matlab code
will rate
Explanation / Answer
#include<stdio.h>
void main(){
int m,n,k,l,i,j,sum=0,p; //m,n represents order of A i.e., mxn
scanf("%d %d %d %d",&m,&n,&k,&l);
int A[m][n],X[k][l],M[m][l]; //A is the matrix and X is a vector and M is the resultant matrix
if(n!=k){
printf("unable to process multiplication ");
return 0;
}
else{
for(i=0;i<m;i++){
for(j=0;j<n;j++){
scanf("%d",&A[i][j]);
}
}
for(i=0;i<k;i++){
for(j=0;j<l;j++){
scanf("%d",&X[i][j]);
}
}
for(i=0;i<m;i++){
for(j=0;j<l;j++){
M[i][j]=0;
}
}
for (i = 0; i < m; i++) {
for (j = 0; j < l; j++) {
for (p = 0; p < n; p++) {
sum = sum + A[i][p]*X[p][j];
}
M[i][j] = sum;
sum = 0;
}
}
for(i=0;i<m;i++){
for(j=0;j<l;j++){
printf("%d ",M[i][j]);
}
}
}
}
/* examples
1.A is of order 2x3 with elements [1 2 3]
[4 5 6]
X is of 3x1 with elements [1]
[2]
[3]
M is of order 2x1 with elemets [14]
[32]
2.A is of order 3x4 with elements [1 2 3 4]
[1 2 3 4]
[1 2 3 4]
X is of 4x1 with elements [1]
[2]
[3]
[4]
M is [30]
[30]
[30]
*/
#include<stdio.h>
void main(){
int m,n,k,l,i,j,sum=0,p; //m,n represents order of A i.e., mxn
scanf("%d %d %d %d",&m,&n,&k,&l);
int A[m][n],X[k][l],M[m][l]; //A is the matrix and X is a vector and M is the resultant matrix
if(n!=k){
printf("unable to process multiplication ");
return 0;
}
else{
for(i=0;i<m;i++){
for(j=0;j<n;j++){
scanf("%d",&A[i][j]);
}
}
for(i=0;i<k;i++){
for(j=0;j<l;j++){
scanf("%d",&X[i][j]);
}
}
for(i=0;i<m;i++){
for(j=0;j<l;j++){
M[i][j]=0;
}
}
for (i = 0; i < l; i++) {
for (j = 0; j < m; j++) {
for (p = 0; p < n; p++) {
sum = sum + A[j][p]*X[p][i];
//printf("%d ",sum);
}
M[j][i] = sum;
sum = 0;
}
}
for(i=0;i<m;i++){
for(j=0;j<l;j++){
printf("%d ",M[i][j]);
}
printf(" ");
}
}
}
#include<stdio.h>
void main(){
int m,n,k,l,i,j,sum=0,p; //m,n represents order of A i.e., mxn
scanf("%d %d %d %d",&m,&n,&k,&l);
int A[m][n],X[k][l],M[m][l]; //A is the matrix and X is a vector and M is the resultant matrix
if(n!=k){
printf("unable to process multiplication ");
return 0;
}
else{
for(i=0;i<m;i++){
for(j=0;j<n;j++){
scanf("%d",&A[i][j]);
}
}
for(i=0;i<k;i++){
for(j=0;j<l;j++){
scanf("%d",&X[i][j]);
}
}
for(i=0;i<m;i++){
for(j=0;j<l;j++){
M[i][j]=0;
}
}
for (i = 0; i < m; i++) {
for (j = 0; j < l; j++) {
for (p = 0; p < n; p++) {
sum = sum + A[i][p]*X[p][j];
}
M[i][j] = sum;
sum = 0;
}
}
for(i=0;i<m;i++){
for(j=0;j<l;j++){
printf("%d ",M[i][j]);
}
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.