# C Program to Find Basis and Dimension of a Matrix

This is a C Program to find the basis and dimension of the given matrix.

Here is source code of the C Program to Find Basis and Dimension of a Matrix. The C program is successfully compiled and run on a Linux system. The program output is also shown below.

1. `#include<stdio.h>`
2. ` `
3. `int main() {`
4. ` `
5. `    int a[3][3], i, j;`
6. ` `
7. `    long determinant;`
8. `    printf("Enter the 9 elements of matrix: ");`
9. `    for (i = 0; i < 3; i++)`
10. `        for (j = 0; j < 3; j++)`
11. `            scanf("%d", &a[i][j]);`
12. ` `
13. `    printf("\nThe matrix is\n");`
14. `    for (i = 0; i < 3; i++) {`
15. `        printf("\n");`
16. `        for (j = 0; j < 3; j++)`
17. `            printf("%d\t", a[i][j]);`
18. `    }`
19. ` `
20. `    determinant = a[0][0] * ((a[1][1] * a[2][2]) - (a[2][1] * a[1][2]))`
21. `            - a[0][1] * (a[1][0] * a[2][2] - a[2][0] * a[1][2]) + a[0][2]`
22. `            * (a[1][0] * a[2][1] - a[2][0] * a[1][1]);`
23. ` `
24. `    if (determinant != 0)`
25. `        printf("The vectors forms the basis of R %d as the determinant is non-zero", 3);`
26. `    else`
27. `        printf("The vectors doesn't form the basis of R %d as the determinant is zero", 3);`
28. ` `
29. `    return 0;`
30. `}`

Output:

```\$ gcc BasisDimension.cpp
\$ ./a.out

Enter the number of vectors:
3
Enter the vectors one by one:
1 2 3
2 3 4
3 4 5
The vectors doesn't form the basis of R3 as the determinant is zero```

Sanfoundry Global Education & Learning Series – 1000 C Programs.