Sunday, February 8, 2015

C Program to find the determinant of a Matrix

C Program to find the determinant of a Matrix  Size id Define By User

#include<conio.h>
#include<stdio.h>

int a[20][20],m;
int determinant(int f[20][20],int a);
int main()
{
  clrscr();
  int i,j;
  printf("----------------------------------------------------------------------\n");
  printf("-----------------CODE BY PROGRAMMING SEEKERZZ ------------------------\n");
  printf("----------------------------------------------------------------------\n");
  printf("\n\nEnter order of matrix : ");
  scanf("%d",&m);
  printf("\nEnter the elements of matrix\n");
  for(i=1;i<=m;i++)
  {
  for(j=1;j<=m;j++)
  {
  printf("a[%d][%d] = ",i,j);
  scanf("%d",&a[i][j]);
  }
  }
  printf("\n\n---------- Matrix A is --------------\n");
  for(i=1;i<=m;i++)
     {
 printf("\n");
 for(j=1;j<=m;j++)
 {
      printf("\t%d \t",a[i][j]);
 }
     }
  printf("\n \n");
  printf("\n Determinant of Matrix A is %d .",determinant(a,m));
  getch();
}

int determinant(int f[20][20],int x)
{
  int pr,c[20],d=0,b[20][20],j,p,q,t;
  if(x==2)
  {
    d=0;
    d=(f[1][1]*f[2][2])-(f[1][2]*f[2][1]);
    return(d);
   }
  else
  {
    for(j=1;j<=x;j++)
    {
      int r=1,s=1;
      for(p=1;p<=x;p++)
{
 for(q=1;q<=x;q++)
   {
     if(p!=1&&q!=j)
     {
b[r][s]=f[p][q];
s++;
if(s>x-1)
{
  r++;
  s=1;
 }
      }
    }
}
     for(t=1,pr=1;t<=(1+j);t++)
     pr=(-1)*pr;
     c[j]=pr*determinant(b,x-1);
     }
     for(j=1,d=0;j<=x;j++)
     {
       d=d+(f[1][j]*c[j]);
      }
     return(d);
   }

}


Share this

1 Comment to "C Program to find the determinant of a Matrix "

Unknown said...

Betway Casino – Welcome Bonus of 200 Free Spins
Betway is 유로 스타 도메인 one of the best names when it 라이브스코어 comes to online casino in the world. Their games 메이피로출장마사지 are varied, generous, and generous 카지노 with 더킹카지노 가입