Wednesday, February 18, 2015

C program to find sum of elements above and below the main digonal of a matrix

C++ program to find sum of elements above and below the main digonal of a matrix

#include<iostream.h>
#include<conio.h>

void main()
{
clrscr();
int arr[5][5],a=0,b=0,i,j,n;
cout<<"Enter size of array(max 5):";
cin>>n;
cout<<"Enter the array:";
for(i=0;i<n;++i)
for(j=0;j<n;++j)
cin>>arr[i][j];


for(i=0;i<n;++i)
for(j=0;j<n;++j)
if(j>i)
a+=arr[i][j];
else
if(i>j)
b+=arr[i][j];

cout<<"
Sum of elements above the digonal:"<<a;

cout<<"
Sum of elements below the digonal:"<<b;

getch();
}

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.