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.

advertisement

Here’s the list of Best Books in C Programming, Data Structures and Algorithms.

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
I’m Manish - Founder and CTO at Sanfoundry. I’ve been working in tech for over 25 years, with deep focus on Linux kernel, SAN technologies, Advanced C, Full Stack and Scalable website designs.

You can connect with me on LinkedIn, watch my Youtube Masterclasses, or join my Telegram tech discussions.

If you’re in your 40s–60s and exploring new directions in your career, I also offer mentoring. Learn more here.