Search This Blog

Translate

C program example Diagonal sum of matrix


C program Diagonal sum of matrix,C program Diagonal and anti diagonal  sum of matrix with source code,C program source code both Diagonal and second diagonal  sum of matrix with source code, recursive c program of diagonal sum of matrix, diagonal sum of matrix using function, recursion, pointers c source code


#include
#include
void main()
{
 int a[100][100];
 int row,col,i,j,sum=0,sum1=0;
 clrscr();
 printf("enter the rows and cols");
 scanf("%d %d",&row,&col);
 if(row==col)
 {
   printf(" \n enter %d by %d matrix",row,col);
   

for(i=0;i <row, i++)    

 for(j=0;i <col, j++)       

   scanf("%d",&a[i][j]);
  
for(i=0;i <row, i++) 

   for(j=0;i <col, j++)      

        {       if(i==j)
                    sum=sum+a[i][j];
           }
   }

   for(i=0,j=col-1;i=0;i++,j--)
      {
       sum1=sum1+a[i][j];
      }

     printf("\n sum of 1st diagonal=%d",sum) ;
     printf("\n sum of 2nd diagonal=%d",sum1) ;

  }


  getch();
}








C Program example List

Google+ Badge