int main ()
{
int i,j,r_sum=0,l_sum=0,a[3][3];
printf("Enter values:\n");
for(i=0;i<3;i++) //input
{
for(j=0;j<3;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("Main Square Matrix\n");
for(i=0;i<3;i++) //main matrix
{
for(j=0;j<3;j++)
{
printf("%d ",a[i][j]);
}
printf("\n");
}
printf("\n\nLeft Diagonal\n");
for(i=0;i<3;i++) //left diagonal
{
printf("%d ",a[i][i]);
}
printf("\n\nRight Diagonal\n");
for(i=0,j=2;j>=0,i<3;j--,i++) //right diagonal
{
printf("%d ",a[i][j]);
}
for(i=0,j=2;j>=0,i<3;j--,i++) // sum
{
l_sum=l_sum+a[i][i];
r_sum=r_sum+a[j][j];
}
printf("\n\nLeft diagonal sum is: %d\n",l_sum);
printf("\nRight diagonal sum is: %d\n",r_sum);
return 0;
}
No comments:
Post a Comment