Home Basic Loop Array string Function Pointer Contact STUDY

AHF    C    PROGRAM    SOLVING

Programming tips

Iterative statement



" ; " after loop



Comment



Header file



Working with switch case




Array 2_D - summation 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,arr1[10][10],arr2[10][10],sum[10][10],row_sum,col_sum; //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(row1!=row2 || col1!=col2) //if the condition is true { pf("\nTHE NUMBER OF ROW AMD COLUMNS OF BOTH MATRIX MUST BE EQUAL."); exit(1); //the program will terminate } row_sum=row1; col_sum=col1; 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]); } //Enter data for second matrix 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]); } //printing the output pf("\n\nThe summation of above two matrix is: "); for(i=0;i < row_sum;i++) { pf("\n"); for(j=0;j < col_sum;j++) { sum[i][j]=arr1[i][j]+arr2[i][j]; pf("\t%d ",sum[i][j]); } } return 0; }
OUTPUT:


© 2018 - All rights reserved