C program to find the sum of 2 matrices ( Program 24)

/*
Made by Anmol main
Student :B.tech CSE 
Punjabi university Patiala
Program No. : 24
*/
#include <stdio.h>
#define m 5
#define n 5
int main()
{
    int i, j, k;
    int arows, acolums, brows, bcolums, sum = 0;
    int a[m][n];
    int b[m][n];
    int p[m][n];
    //getting input of two matrices from the user
    printf("\nEnter the number of rows : ");
    scanf("%d", &arows);
    printf("Enter the number of colums : ");
    scanf("%d", &acolums);

    for (i = 0; i < arows; i++)
    {
        for (j = 0; j < acolums; j++)
        {
            scanf("%d", &a[i][j]);
        }
    }
    printf("\nEnter the number of rows : ");
    scanf("%d", &brows);
    printf("Enter the number of colums : ");
    scanf("%d", &bcolums);
    if (arows == bcolums)
    {
        for (i = 0; i < arows; i++)
        {
            for (j = 0; j < acolums; j++)
            {
                scanf("%d", &b[i][j]);
            }
        }
        //input completed
        //printing two matrices
        printf("\n\nYou entered matrix A :\n");
        for (i = 0; i < arows; i++)
        {
            printf("\n");
            for (j = 0; j < acolums; j++)
            {
                printf("%d ", a[i][j]);
            }
        }
        printf("\n\nYou entered matrix B :\n");
        for (i = 0; i < brows; i++)
        {
            printf("\n");
            for (j = 0; j < bcolums; j++)
            {
                printf("%d ", b[i][j]);
            }
        }
        //printing of two matrices completed
        //printing the sum of two matrtices
        for (i = 0; i < arows; i++)
        {
            printf("\n");
            for (j = 0; j < bcolums; j++)
            {
                p[i][j] = a[i][j] + b[i][j];
            }
        }
        for (i = 0; i < arows; i++)
        {
            printf("\n");
            for (j = 0; j < bcolums; j++)
            {
                printf("%d ", p[i][j]);
            }
        }
    }
}

Comments

Popular posts from this blog

Glowing-Log-in-window-in-Pure-html-css #30

Mouse Hover Effect in Html CSS and Javascript #27

Recipie book in c language with text animiations - Source code ( Program - 18 )