#include<iostream>
using namespace std;
int main()
{
int n, m, i, j, sum = 0;
cout << "Enter Array Row & Column : ";
cin >> n >> m;
cout << endl;
int a[n][m];
cout << "Enter Array Element :: \n";
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
cin >> a[i][j];
}
}
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
if(i == j)
{
sum = sum + a[i][j];
}
}
}
cout << "Sum of Diagonal Element of Given Matrix :: " << sum << endl;
return 0;
}
using namespace std;
int main()
{
int n, m, i, j, sum = 0;
cout << "Enter Array Row & Column : ";
cin >> n >> m;
cout << endl;
int a[n][m];
cout << "Enter Array Element :: \n";
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
cin >> a[i][j];
}
}
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
if(i == j)
{
sum = sum + a[i][j];
}
}
}
cout << "Sum of Diagonal Element of Given Matrix :: " << sum << endl;
return 0;
}
Comments
Post a Comment