Saturday, 5 May 2012

Trace and Normal of the Matrix in C


#include<stdio.h>
#include<conio.h>
main()
{
      int n,i,j,r,c;
      int a[10][10];
      float trace=0,sum=0,normal;
      printf("Enter the order of the matrix\n");
      scanf("%d%d",&r,&c);
      printf("Enter the elements of the matrix\n");
      for(i=0;i<r;i++)
      {
                      for(j=0;j<c;j++)
                      {
                                      scanf("%d",&a[i][j]);
                      }
      }
      for(i=0;i<r;i++)
      {
                       for(j=0;j<c;j++)
                       {
                                       if(i==j)
                                       {
                                               trace+=a[i][j];
                                       }
                                       sum+=pow(a[i][j],2);
                       }
      }
      normal=sqrt(sum);
      printf("Trace of the matrix = %f\n",trace);
      printf("Normal of the matrix = %d\n",normal);
      getch();
      return 0;
}
                                       
                                       
                      
                      

No comments:

Post a Comment