Home Basic Loop Array string Function Pointer Contact STUDY

AHF    C    PROGRAM    SOLVING

Programming tips

Header file



Comment



Working with switch case



" ; " after loop



Specifer




Array 2_D - multiplication of two ( m * n ) matrix




// AHF C PROGRAM SOLVING

//solving here 2_D   ARRAY 	programming problem

#include<stdio.h> #include<math.h> #include<stdlib.h> #define pf printf int main() { int row1,row2,col1,col2,i,j,k,arr1[10][10],arr2[10][10],mul[10][10],row_mul,col_mul; //taking the dimension of the first array pf("Enter the number of rows in the first matrix: "); scanf("%d",&row1); pf("\nEnter the number of columns in the first matrix: "); scanf("%d",&col1); //taking the dimension of the second array pf("\nEnter the number of rows in the second matrix: "); scanf("%d",&row2); pf("\nEnter the number of columns in the second matrix: "); scanf("%d",&col2); //checking if the two matrix are eligible summation or not if(col1!=row2) //if the condition is true { pf("\nTHE NUMBER OF COLUMNS IN THE FIRST MATRIX MUST BE EQUAL TO NUMBER OF ROW IN SECOND MATRIX."); exit(1); //the program will terminate } row_mul=row1; col_mul=col2; pf("\nEnter the element of two matrix with column major order: "); //taking data for first element pf("\n*****************************************************************************************"); pf("\n\nEnter the element of first matrix: "); for(i=0;i < row1;i++) { for(j=0;j < col1;j++) scanf("%d",&arr1[i][j]); } //taking data for second element pf("\n\nEnter the element of second matrix: "); for(i=0;i < row2;i++) { for(j=0;j < col2;j++) scanf("%d",&arr2[i][j]); } pf("\n\nThe multiplies of above two matrix is: "); for(i=0;i < row_mul;i++) { for(j=0;j < col_mul;j++) { mul[i][j]=0; for(k=0;k < col_mul;k++) mul[i][j]+=arr1[i][k]*arr2[k][j]; //multiplication is done with row of first matrix and column of second matrix } } //printing the new array of multiplication for(i=0;i < row_mul;i++) { pf("\n"); for(j=0;j < col_mul;j++) pf("\t%d ",mul[i][j]); } return 0; }
OUTPUT:


© 2018 - All rights reserved