Twitter Feed Facebook Google Plus Youtube

Adsense responsive

Recent Post below header

Tuesday 29 January 2013

C PROGRAM: TO CALCULATE SUM OF ELEMENTS OF MAIN DIAGONAL OF SQUARE MATRIX

CODING:
#include<stdio.h>
#include<conio.h>
void main()
{
int a[10][10],m,i,j,sum=0;
clrscr();
printf("Enter order of square matrix ");
scanf("%d",&m);
printf("Enter values of matrix\n");
for(i=1;i<=m;i++)
{
 for(j=1;j<=m;j++)
 {
  printf("Enter value of a[%d][%d] ",i,j);
  scanf("%d",&a[i][j]);
 }
}
for(i=1;i<=m;i++)
{
 for(j=1;j<=m;j++)
 {
  if(i==j)
  sum=sum+a[i][j];
 }
}
printf("\nSum of elements of main daigonal of matrix = %d",sum);
getch();
}


CODING


OUTPUT


For any query or suggestion comment below...

No comments:

Post a Comment