C Program to Add Two Matrices Using Multi-dimensional Arrays.| Add Two Matrices


Aim:- Write a program to add two matrices. (Using 2-D arrays)

Source Code:-

#include<Stdio.h>
 int main()
{           
int a[10][10],b[10][10],c[10][10],m,n,i,j;
    printf("Enter the order the matrix=");
            scanf("%d%d",&m,&n);
            printf("Enter the element of first matrix=\n");
            for(i=0;i<m;i++)
            for(j=0;j<n;j++)
            scanf("%d",&a[i][j]);
            printf("Enter the 2nd matrix=\n");
            for(i=0;i<m;i++)
            for(j=0;j<n;j++)
            scanf("%d",&b[i][j]);
            for(i=0;i<m;i++)
            for(j=0;j<n;j++)
            c[i][j]=a[i][j]+b[i][j];
            printf("Resultant matrix is=\n");
            for(i=0;i<m;i++)
                        {
                        for(j=0;j<n;j++)
                        printf("%d",c[i][j]);
}
 printf("\n");
return 0;
 }
Output


Related post:-

Post a Comment

0 Comments

Copyright (c) 2019 Designed by Shubham tiwari All Right Reseved