When can two matrices of order m x n and p x q be multiptied? Also write a program in ‘C’ to multiply two such matrices. 10m Dec2008

By | April 14, 2016

When can two matrices of order m x n and p x q be multiptied? Also write a program in ‘C’ to multiply two such matrices. 10m Dec2008

 

The only condition which makes matrix multiplication possible is n should be equal to p (i.e. n==p) n of m x n Matrix and p of p x q Matrix

 

Code:

#include<stdio.h>
void main()
{
int A[3][3],B[3][3],C[3][3],I,J,K;
clrscr();
printf(“ENTER 3X3 MATRIX A VALUES\n”);
for(I=0;I<3;I++)
{
for(J=0;J<3;J++)
{
scanf(“%d”,&A[I][J]);
}
}
printf(“ENTER 3X3 MATRIX B VALUES\n”);
for(I=0;I<3;I++)
{
for(J=0;J<3;J++)
{
scanf(“%d”,&B[I][J]);
}
}
for(I=0;I<3;I++)
{
for(J=0;J<3;J++)
{
C[I][J]=0;
for(K=0;K<3;K++)
{
C[I][J]=C[I][J]+A[I][K]*B[K][J];
}
}
}
printf(“RESULT 3X3 MATRIX C VALUES ARE :\n”);
for(I=0;I<3;I++)
{
for(J=0;J<3;J++)
{
printf(“%d\t”,C[I][J]);
}
printf(“\n”);
}
getch();
}

[codesyntax lang=”c”]

#include<stdio.h>
void main()
{
int A[3][3],B[3][3],C[3][3],I,J,K;
clrscr();
printf(“ENTER 3X3 MATRIX A VALUES\n”);
for(I=0;I<3;I++)
{
for(J=0;J<3;J++)
{
scanf(“%d”,&A[I][J]);
}
}
printf(“ENTER 3X3 MATRIX B VALUES\n”);
for(I=0;I<3;I++)
{
for(J=0;J<3;J++)
{
scanf(“%d”,&B[I][J]);
}
}
for(I=0;I<3;I++)
{
for(J=0;J<3;J++)
{
C[I][J]=0;
for(K=0;K<3;K++)
{
C[I][J]=C[I][J]+A[I][K]*B[K][J];
}
}
}
printf(“RESULT 3X3 MATRIX C VALUES ARE :\n”);
for(I=0;I<3;I++)
{
for(J=0;J<3;J++)
{
printf(“%d\t”,C[I][J]);
}
printf(“\n”);
}
getch();
}

[/codesyntax]

 Screen Shots:

C_program_Matrix_Multiplication

 C_program_Matrix_Multiplication_Output                                                       

 

2. (a) Write a program in ‘C’ to generate a progress report for students which displays the total marks, avetage, and grades. The input for the system is marks secured in five courses (Assignment and Term end Examination). Pass (40%) in both the components are compulsory. Grades may be given accordingly. Assumptions can be made if necessary and specify them. 10

Similar program can be found on this link http://cssimplified.com/c-programming/a-c-program-to-process-the-students-evolution-records-using-structures

 

(b) What is the difference between ” &” and. “&&’? Explain with an example. 5       

Solved program can be found on this link http://cssimplified.com/c-programming/explain-use-of-comma-operator-in-c-and-what-is-the-difference-between-and