C Program to find the Sum of two n x n Matrices

 


// Program by Akash Tripathi (@proakash256) 
#include <stdio.h>
int main()
{
    int r;
    printf("Enter the number of Rows and Columns: ");
    scanf("%d" , &r);
    int ar1[r][r];
    int ar2[r][r];
    printf("\nEnter the elements (row wise) of the First Matrix:\n");
    for(int i = 0i < ri = i + 1)
        for(int j = 0j < rj = j + 1)
            scanf("%d" , &ar1[i][j]);
    printf("\nEnter the elements (row wise) of the Second Matrix:\n");
    for(int i = 0i < ri = i + 1)
        for(int j = 0j < rj = j + 1)
            scanf("%d" , &ar2[i][j]);
    printf("\nThe First Matrix is :\n\n");
    for(int i = 0i < ri = i + 1)
    {
        for(int j = 0j < rj = j + 1)
            printf("%d\t" , ar1[i][j]);
        printf("\n");
    }
    printf("\nThe Second Matrix is :\n\n");
    for(int i = 0i < ri = i + 1)
    {
        for(int j = 0j < rj = j + 1)
            printf("%d\t" , ar2[i][j]);
        printf("\n");
    }
    printf("\nThe Sum of both the matrices is :\n\n");
    for(int i = 0i < ri = i + 1)
    {
        for(int j = 0j < rj = j + 1)
            printf("%d\t" , (ar1[i][j] + ar2[i][j]));
        printf("\n");
    }
    printf("\n");
    return 0;
}

Comments