Tuesday, October 06, 2015

Write a program to read two 3 × 3 matrices and calculate and display the sum of those two matrices.

Solution:-
#include<stdio.h>
#include<conio.h>
void main( )
{
       clrscr( );
       int i,j,total;
       int matrix[3][3],matrix1[3][3],sum[3][3];
       printf("Enter the 3*3 matrix \n");
       for(i=0;i<3;i++)
            {
                     for(j=0;j<3;j++)
                    {
                            scanf("%d",&matrix[i][j]);
                     }
             }
        printf("Enter the 3*3 matrix1 \n");
        for(i=0;i<3;i++)
        {
                 for(j=0;j<3;j++)
                {
                       scanf("%d",&matrix1[i][j]);
                 }
        }
        for(i=0;i<3;i++)
       {
                 for(j=0;j<3;j++)
                {
                        sum[i][j]=matrix[i][j]+matrix1[i][j];
                 }
        }
        for(i=0;i<3;i++)
        {
                  for(j=0;j<3;j++)
                 {
    
                        printf("%d\t ",sum[i][j]);
                 }
                 printf("\n");
        }
        getch( );
}