Created
May 21, 2014 08:39
-
-
Save Manume/997428585c60a7a81d7c to your computer and use it in GitHub Desktop.
programs for sum of diagonal elements
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream.h> | |
#include <conio.h> | |
void main() | |
{ | |
clrscr(); | |
int x; | |
int A[4][4],sum=0; //Reading the matrix. | |
cout << "Enter the elements of the matrix : " << endl; | |
for(int y=0;y<4;y++) | |
for (int x=0;x<4;x++) | |
{ | |
cout << "Element " << x+1 << ", " << y+1 << " : "; | |
cin>>A[x][y]; | |
} | |
//Sum of either of the diagonal elements. | |
for(x=0;x<4;x++) | |
for(y=0;y<4;y++) | |
if(x==y) | |
sum+=A[x][y]; | |
else if(y==4-(1+1)); | |
sum+=A[x][y]; | |
cout << "Sum of either of the diagonal elements is : " << sum; | |
getch(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment