adsense

Hii, welcome to my site. My name is Om prakash kartik. This blog helps you to learn programming languages concepts.

c program to find the trace of a given square matrix

C program to find the trace of a given square matrix 

#include<stdio.h>
#include<conio.h>
 int main()
  {
    int a[5][5],r,c,i,j,sum=0;
    printf("Enter a number of rows and columns:-");
    scanf("%d%d",&r,&c);
    if(r==c)
     {
      printf("\nEnter %d*%d elements in matrix:-\n",r,c);
      for(i=0;i<r;i++)
        {
  for(j=0;j<c;j++)
      scanf("%d",&a[i][j]);
  }
       for(i=0;i<r;i++) 
     sum=sum+a[i][i];
  printf("\nTrace of the matrix = %d",sum); 
      }
     else
  printf("Not a square matrix. It is not possible to find trace.");  
   return 0;
  }


Output:-




Related program of Matrix

  1.  Write a program in C to find the transpose of given matrix.
  2.  Write a program in C to add two matrix.
  3.  Write a program in C to find the inverse of the given matrix.


Post a Comment

0 Comments