बिजनेस मार्केटिंग का लो कॉस्ट फंडा , अपने मोबाइल से ऑटो sms भेजकर मार्केटिंग करे विजिट करे http://autotextsms.com/ बिजनेस मार्केटिंग का लो कॉस्ट फंडा http://autotextsms.com/

Search This Blog

Translate

C Program to multiply two matrices using multidimensional arrays

C Program to multiply two matrices using multidimensional arrays 


#include <stdio.h>
 int main()
{ int a[10][10], b[10][10], mult[10][10], r1, c1, r2, c2, i, j, k; printf("Enter rows and column for first matrix: "); scanf("%d%d", &r1, &c1); printf("Enter rows and column for second matrix: "); scanf("%d%d",&r2, &c2); while (c1!=r2) { printf("Error! column of first matrix not equal to row of second.\n\n"); printf("Enter rows and column for first matrix: "); scanf("%d%d", &r1, &c1); printf("Enter rows and column for second matrix: "); scanf("%d%d",&r2, &c2); } printf("\nEnter elements of matrix 1:\n"); for(i=0; i<r1; ++i) for(j=0; j<c1; ++j) { printf("Enter elements a%d%d: ",i+1,j+1); scanf("%d",&a[i][j]); } printf("\nEnter elements of matrix 2:\n"); for(i=0; i<r2; ++i) for(j=0; j<c2; ++j) { printf("Enter elements b%d%d: ",i+1,j+1); scanf("%d",&b[i][j]); } for(i=0; i<r1; ++i) for(j=0; j<c2; ++j) { mult[i][j]=0; } for(i=0; i<r1; ++i) for(j=0; j<c2; ++j) for(k=0; k<c1; ++k) { mult[i][j]+=a[i][k]*b[k][j]; } printf("\nOutput Matrix:\n"); for(i=0; i<r1; ++i) for(j=0; j<c2; ++j) { printf("%d ",mult[i][j]); if(j==c2-1) printf("\n\n"); } return 0; }


OUTPUT:- ----------------------------
 Enter rows and column for first matrix: 3 3 Enter rows and column for second matrix: 3 3 Enter elements of matrix 1: Enter elements a11: 1 Enter elements a12: 3 Enter elements a13: 5 Enter elements a21: 3 Enter elements a22: 1 Enter elements a23: 3 Enter elements a31: 6 Enter elements a32: 7 Enter elements a33: 8 Enter elements of matrix 2: Enter elements b11: 2 Enter elements b12: 9 Enter elements b13: 0 Enter elements b21: 8 Enter elements b22: 4 Enter elements b23: 5 Enter elements b31: 1 Enter elements b32: 3 Enter elements b33: 4 Output Matrix: 31 36 35 17 40 17 76 106 67

--------------------------------


C Program example List