-->
Showing posts with label WAP to find sum of two matrices. Here pass matrix as parameter.. Show all posts
Showing posts with label WAP to find sum of two matrices. Here pass matrix as parameter.. Show all posts

WAP to find sum of two matrices. Here pass matrix as parameter.

in turboc++
-------------------------------------------------------------------------------------------------------
//WAP to find sum of two matrices of order mxn. Here pass matrix as parameter.
#include<stdio.h>
#include<conio.h>
void sum_of_matrix(int matrix[100][100],int matrix1[100][100],int row,int col);//function prototype
int main()
{
int mat1[100][100],mat2[100][100];              //matrix declaration of max size 100x100
int i,j;
int total_row,total_col;             //declaration of variable
printf("enter total number of rows(m)\n");
scanf("%d",&total_row);                     // for total number of rows of matrix
printf("enter total columns(n)\n");;
scanf("%d",&total_col);                     // for total number of columns of matrix
printf("enter elements of first matrix mat1\n");
for(i=0;i<total_row;i++)
{
  for(j=0;j<total_col;j++)                  // nested loop for input of elements
       {
           scanf("%d",&mat1[i][j]);   // getting inputs from user
        }
}
printf("enter elements of second matrix mat2\n");
for(i=0;i<total_row;i++)
{
  for(j=0;j<total_col;j++)                  // nested loop for input of elements
       {
           scanf("%d",&mat2[i][j]);   // getting inputs from user
        }
}

sum_of_matrix(mat1,mat2,total_row,total_col);//function calling
getch();

return 0;
}

void sum_of_matrix(int matrix[100][100],int matrix1[100][100],int row,int col)
{
    int i,j;
printf("sum of two matrices are\n");
for(i=0;i<row;i++)
{
  for(j=0;j<col;j++)           
       {
           printf(" %d ",matrix[i][j]+matrix1[i][j]); // sum and display of matrix
        }
        printf("\n");                    // display in next row
}
getch();
}