Determinant 2x2 and 3x3 in C program
#include <stdio.h>
#include <stdlib.h>
void determinant3x3(){
printf ("Determinant of 3x3 :\n");
int i,j;
int a[10][10];
int det=0;
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
printf("Input your data [%d][%d]",i,j);
scanf("%d",&a[i][j]);
}
}
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
printf("%d\t ",a[i][j]);
}
printf("\n");
}
for (int i=0;i<3;i++){
det= det+ ( a[0][i]*(a[1][(i+1)%3]*a[2][(i+2)%3]-a[1][(i+2)%3]*a[2][(i+1)%3]));
}
printf("\nThe value of determinant is %d\n",det);
}
void determinant2x2(){
printf ("\nCalculator determinant 2 x 2 of Matxi\n");
int i,j,a[10][10],determinant=0;
float s;
printf ("Please input element 2 x 2 of matrix\n");
for (int i=0; i<2; i++){
for (int j=0; j<2; j++){
printf("[%d][%d]",i,j);
scanf ("%d",&a[i][j]);
}
}
for ( int i=0; i<2; i++){
for ( int j=0; j<2; j++){
printf ("%d\t",a[i][j]);
}
printf("\n");
}
for (int i=0; i<2; i++){
determinant = a[0][0]*a[1][1] - a[1][0]*a[0][1];
}
printf ("Determinant of Matrix 2 x 2:%d",determinant);
}
int main()
{
printf ("Option1 Determinant 2 x 2:");
printf ("\nOption2 Determinant 3 x 3:\n");
int choice ;
printf ("Choose your Option:");
scanf ("%d",&choice);
if (choice ==1){
determinant2x2();
}
else if (choice ==2){
determinant3x3();
}
return 0;
}
Output
0 Comments