OCJP

Total of Diagonal in Matrix

#include<stdio.h>
#include<conio.h>
#define R 3
#define C 3
void main()
{
int mat[R][C];
int i,j,d1=0,d2=0;
clrscr();
printf("\n enter %d value",R*C);
for(i=0;i<R;i++)
{
for(j=0;j<R;j++)
{
scanf("%d",&mat[i][j]);
	if(i==j)
	d1+=mat[i][j];

	if((i+j)==(R-1))
	{
	d2+=mat[i][j];
	}

}
}

printf("\nDiagonal 1 Total %d",d1);
printf("\nDiagonal 2 Total %d",d2);
getch();
}

Leave a Reply

Your email address will not be published. Required fields are marked *


× How can I help you?