Saturday 28 June 2014

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


Here is a C++ program to find sum of diagonal elements of matrix


 SOURCE CODE OUTPUT
#include<iostream>
using namespace std;
int main()
{
    int a[10][10],order,sum=0;
    cout<<"Enter order of matrix (max 10*10): ";
    cin>>order;
    cout<<"Enter matrix a1 : "<<endl;
    for(int i=0;i<order;i++)
        for(int j=0;j<order;j++)
           cin>>a[i][j];
    for(int i=0;i<order;i++)
        sum+=a[i][i];
    cout<<"Sum of diagonal elements of matrix : "<<sum;
    return 0;
}

Any questions regarding to program please write in comments.

No comments:

Post a Comment