Showing posts with label 2x2. Show all posts
Showing posts with label 2x2. Show all posts

C Program to Calculate Determinant of Matrix of Order Upto 3

In this post i am sharing a C program to calculate determinant of matrices of order upto 3 (3x3).

#include<stdio.h>


void main()

{int a[10][10],i,m,j;

int det=0; 

printf("\nEnter the order of matrix:\n "); 

scanf("%i",&m);

printf("\nenter elements\n");

for(i=0;i<m;i++)

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

printf("\nThe matrix is\n");

for(i=0;i<m;i++)

{
printf("\n");

for(j=0;j<m;j++)
printf("%3d",a[i][j]);

}

printf("\nthe transpose is\n");

for(i=0;i<m;i++)
{
for(j=0;j<m;j++)

printf("%3i",a[j][i]);

printf("\n");

}

if(m==1)

{
det=a[0][0];

printf("det=%i",det);

}