C C++ program to find sum of all elements of matrix

C C++ program to find sum of all elements of matrix

Procedure Oriented Programming (POP) और Object Oriented Programming (OOP) में अंतर जानने के लिए देखें—POP vs OOP

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

Function क्या है इसका प्रयोग क्यो किया जाता है यह कितने प्रकार का होता है जानने के लिए देखें—Functions in C

C program to find sum of all elements of matrix

#include<stdio.h>
int main()
{
    int m[3][3],i,j,sum=0;
    printf("Enter elements of Matrix:\n");
    for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
        {
            scanf("%d",&m[i][j]);
        }
    }
    for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
        {
            sum=sum+m[i][j];
        }
    }
    printf("Sum of all elements = %d",sum);
    return 0;
}

C++ program to find sum of all elements of matrix

#include<iostream>
using namespace std;
int main()
{
    int m[3][3],i,j,sum=0;
    cout<<"Enter elements of Matrix:\n";
    for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
        {
            cin>>m[i][j];
        }
    }
    for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
        {
            sum=sum+m[i][j];
        }
    }
    cout<<"Sum of all elements = "<<sum;
    return 0;
}

Output of C C++ program to find sum of all elements of matrix

C C++ program to find sum of all elements of matrix

Some useful matrix programs in C C++

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

Published by

admin

I am a computer teacher, programmer and web developer