The program is a C program that performs matrix multiplication on two matrices of size r x c. The program takes input for the number of rows and columns in the matrices and the elements of the matrices from the user. The program uses nested for loops to perform the matrix multiplication and stores the result in a new matrix "m". The program then prints the result matrix on the screen.
In detail, the program first prompts the user to enter the number of rows and columns in the matrices. It then prompts the user to enter the elements of the two matrices, "a" and "b" using two nested for loops. Next, the program uses another nested for loop to perform the matrix multiplication. The program multiplies the corresponding elements of the matrices "a" and "b" and stores the result in the new matrix "m". The program then prints the resulting matrix "m" on the screen.
#include<stdio.h> int main() { int a[5][5],b[5][5],m[5][5]; int i,j,r,c,t,k; printf("\nEnter No of Rows : "); scanf("%d",&r); printf("\nEnter No of Columns : "); scanf("%d",&c); printf("\nEnter A Matrix : "); for(i=0;i<r;i++) { for(j=0;j<c;j++) { scanf("%d",&a[i][j]); } } for(i=0;i<r;i++) { for(j=0;j<c;j++) { printf("\t%d",a[i][j]); } printf("\n"); } printf("\nEnter B Matrix : "); for(i=0;i<r;i++) { for(j=0;j<c;j++) { scanf("%d",&b[i][j]); } } for(i=0;i<r;i++) { for(j=0;j<c;j++) { printf("\t%d",b[i][j]); } printf("\n"); } for(i=0;i<r;i++) { for(j=0;j<c;j++) { t=0; for(k=0;k<c;k++) { t+=(a[i][k]*b[k][j]); } m[i][j]=t; } } printf("\nResult Matrix : \n"); for(i=0;i<r;i++) { for(j=0;j<c;j++) { printf("\t%d",m[i][j]); } printf("\n"); } return 0; }To download raw file Click Here
Enter No of Rows : 2 Enter No of Columns : 2 Enter A Matrix : 2 3 4 5 2 3 4 5 Enter B Matrix : 5 6 7 8 5 6 7 8 Result Matrix : 31 36 55 64
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions