Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Here is the problem: Write a C program to accept two M*N Matrices A and B that w

ID: 642458 • Letter: H

Question

Here is the problem:

Write a C program to accept two M*N Matrices A and B that will provided in row majoring ordering. The demensions of these matrices an the (float and double) values will be provided one after the other. Accept two more float or double values p and q from the user compute the Matrix.

C = A - pA +qB. Display the result of matrix C.

This is what I have so far! and I would like to change it so the user can enter the p and q values!

#include<stdio.h>
#define MYSIZE 6;

double myA[MYSIZE][MYSIZE];
double myB[MYSIZE][MYSIZE];
double myC[MYSIZE][MYSIZE];
double p = 2;
double q = 3;
int i,j,k;
int count;

void printMatrix(int iLimit, int jLimit, double myMat[iLimit][jLimit]){
   int i;
   int j;
   printf(" ");
   i = 0;
   while (i < iLimit){
       j = 0;
       while(j < jLimit){
           printf("%11lf", myMat[i][j]);
           j = j + 1;
       }
       printf(" ");
       i = i + 1;
   }
}  
int main(void){
   i = 0;
   while (i <= MYSIZE){
       j = 0;
       while (j < MYSIZE){
           scanf("%lf", &myA[i][j]);
           j = j + 1;
       }
       i = i + 1;
   }
printMatrix(MYSIZE,MYSIZE,myA);
   i = 0;
   while (i <= MYSIZE){
       j = 0;
       while (j < MYSIZE){
           scanf("%lf", &myB[i][j]);
           j = j + 1;
       }
       i = i + 1;
   }
printMatrix(MYSIZE,MYSIZE,myB);
i = 0;
while (i < MYSIZE){
   j = 0;
   while (j < MYSIZE){
       myC[i][j]= 0;
       k = 0;
       while (k < MYSIZE){
           myC[i][j] = myC[i][j] + myA[i][j] - p * myA[k][j] + q * myB[k][j];
           k = k + 1;
       }
   j =j + 1;
  
   }
   i = i + 1;
}
printMatrix(MYSIZE,MYSIZE,myC);
return 0;

}

Explanation / Answer

#include<stdio.h>
#define MYSIZE 2

double myA[MYSIZE][MYSIZE];
double myB[MYSIZE][MYSIZE];
double myC[MYSIZE][MYSIZE];
double p = 2;
double q = 3;
int i,j,k;
int count;

void printMatrix(int iLimit, int jLimit, double myMat[][MYSIZE]){
int i;
int j;
printf(" ");
i = 0;
while (i < iLimit){
j = 0;
while(j < jLimit){
printf("%11lf", myMat[i][j]);
j = j + 1;
}
printf(" ");
i = i + 1;
}
}
int main(void){
i = 0;
printf("ENTER p: ");
scanf("%d", &p);
printf("ENTER q: ");
scanf("%d", &q);


printf("ENTER MATRIX A: ");
while (i < MYSIZE){
j = 0;
while (j < MYSIZE){
scanf("%lf", &myA[i][j]);
j = j + 1;
}
i = i + 1;
}
printMatrix(MYSIZE,MYSIZE,myA);

printf("ENTER MATRIX B: ");
i = 0;
while (i < MYSIZE){
j = 0;
while (j < MYSIZE){
scanf("%lf", &myB[i][j]);
j = j + 1;
}
i = i + 1;
}
printMatrix(MYSIZE,MYSIZE,myB);
printf("OUTPUT MATRIX C: ");
i = 0;
while (i < MYSIZE){
j = 0;
while (j < MYSIZE){
myC[i][j]= 0;

myC[i][j] = myA[i][j] - p * myA[i][j] + q * myB[i][j];
  
j =j + 1;
  
}
i = i + 1;
}
printMatrix(MYSIZE,MYSIZE,myC);
return 0;

}