C C++ program to find addition of two matrix

C C++ program to find addition of two matrix

Looping और iterative statements के बारे में और अधिक जानने के लिए देखें— Looping statements in C

If statement और decision making statements के बारे में अधिक जानने के लिए देखें— If statements in C

C Language में Array और इसके विभिन्न प्रकारो के बारे में और अधिक जानने के लिए देखें— Arrays in C

C program to find addition of two matrix

#include<stdio.h>
int main()
{
    int a[3][3],b[3][3],r[3][3],i,j;
    printf("Enter Values of Matrix 1:\n");
    for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
        {
            scanf("%d",&a[i][j]);
        }
    }
    printf("Enter Values of Matrix 2:\n");
    for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
        {
            scanf("%d",&b[i][j]);
        }
    }
    for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
        {
            r[i][j]=a[i][j]+b[i][j];
        }
    }
    printf("Addition of Matrix:\n");
    for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
        {
            printf("%d\t",r[i][j]);
        }
        printf("\n");
    }
    return 0;
 }

C++ program to find addition of two matrix

#include<iostream>
using namespace std;
int main()
{
    int a[3][3],b[3][3],r[3][3],i,j;
    cout<<"Enter Values of Matrix 1 :\n";
    for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
        {
            cin>>a[i][j];
        }
    }
    cout<<"Enter Values of Matrix 2 :\n";
    for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
        {
            cin>>b[i][j];
        }
    }
    for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
        {
            r[i][j]=a[i][j]+b[i][j];
        }
    }
    cout<<"Addition of Matrix:\n";
    for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
        {
            cout<<r[i][j]<<"\t";
        }
        cout<<"\n";
    }
    return 0;
 }

Output of C C++ program to find addition of two matrix

C C++ program to find addition of two matrix

Other matrix programs in C C++

  1. Transpose of Matrix
  2. Multiplication of two matrix
  3. Sum of elements of matrix
Share it to:

Published by

admin

I am a computer teacher, programmer and web developer