First of all the output of the program is:
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<stdio.h> | |
#include<conio.h> | |
int main() | |
{ | |
int a,b,n1[10][10],n,sum=0; | |
printf("enter the order of the matrix you want\n"); | |
scanf("%d",&n); | |
printf("enter the element of the matrix\n"); | |
for(a=0;a<n;a++) | |
{ | |
for(b=0;b<n;b++) | |
{ | |
scanf("%d",&n1[a][b]); | |
} | |
} | |
for(a=0;a<n;a++) | |
{ | |
for(b=0;b<n;b++) | |
{ | |
printf("%d",n1[a][b]); | |
} | |
printf("\n"); | |
} | |
for(a=0;a<n;a++) | |
{ | |
for(b=0;b<n;b++) | |
{ | |
if(a==b||(a+b)==(n-1)) | |
sum=sum+n1[a][b]; | |
} | |
} | |
printf("\n the sum of the diagonal elements is %d",sum); | |
getch(); | |
} | |
0 comments :
Post a Comment