TechArena Community Calculating Matrix Determinant in C

#1
09-05-2009
 Member Join Date: Apr 2009 Posts: 29
Calculating Matrix Determinant in C

Enter a 2x2 matrix of integers, calculate and display the determinant.
Tables with more than two dimensions: Proceed in the same way by adding elements of design.That restores my C code but I don't know what is the problem in the code.
Code:
``` # include <stdio.h>
# include <conio.h>

int determinant (int m [1] [1])
(
return ((m [0] [0] * m [1] [1]) - (m [1] [0] * m [0] [1]));
)
void main ()
(
int M [1] [1], i, j;

for (i = 0; i <= 1; i + +)
for (j = 0 j <= 1 j + +)
(
printf ( "Donez the value of M [% d] [% d]:", i + 1, j + 1);
scanf ( "% d", & M [i] [j]);
)
printf ( "and determine the% d", determinant (M));
getch ();
return 0;
)```
#2
09-05-2009
 Member Join Date: May 2008 Posts: 2,008
Re: Calculating Matrix Determinant in C

Debug :

Code:
```  E: \ l Angaga C \ a \ main.c | 13 | warning: return type of 'main' is not `int '|
E: \ C \ a \ main.c | | In function `main ': |
E: \ l Angaga C \ a \ main.c | 25 | warning: `return 'with a value, in function returning void |```
0 errors with 2 warnings
#3
09-05-2009
 Member Join Date: May 2008 Posts: 2,293
Re: Calculating Matrix Determinant in C

For additional dimensions, we can easily do so by recursion (through the development of row or column), although this is not really optimal.
#4
09-05-2009
 Member Join Date: Apr 2009 Posts: 29
Re: Calculating Matrix Determinant in C

Code:
` int main (void);`

and warnings disappears!

in the running it gives:

Code:
``` Donez the value of M [1] [1]: 1
Donez the value of M [1] [2]: 2
Donez the value of M [2] [1]: 3
Donez the value of M [2] [2]: 4
and -5 determine the```

 Tags: