Created
June 15, 2020 05:45
-
-
Save sivsivsree/c116dfc8dcb502b89647c965bceab0af to your computer and use it in GitHub Desktop.
This file contains hidden or 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<stdio.h> | |
#define SIZE 3 // 3x3 matrix | |
int main() | |
{ | |
int A[SIZE][SIZE]; | |
int row, col, sum = 0; | |
int DSum = 0; | |
printf("Enter elements in matrix of size %dx%d: \n", SIZE, SIZE); | |
for(row=0; row<SIZE; row++){ | |
for(col=0; col<SIZE; col++){ | |
scanf("%d", &A[row][col]); | |
} | |
} | |
/* Calculate sum of elements of each row of matrix */ | |
for(row=0; row<SIZE; row++){ | |
sum = 0; | |
for(col=0; col<SIZE; col++){ | |
sum += A[row][col]; | |
} | |
printf("Sum of elements of Row %d = %d\n", row+1, sum); | |
} | |
for(row=0; row<SIZE; row++){ | |
sum = 0; | |
for(col=0; col<SIZE; col++){ | |
sum += A[col][row]; | |
} | |
printf("Sum of elements of Column %d = %d\n", row+1, sum); | |
} | |
for(row = 0; row < SIZE; row++){ | |
DSum = DSum + A[row][row]; | |
} | |
printf("\nThe diagonal sum = %d", DSum ); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment