Write a program to evaluate a determinant of any order n*n.

Write a program to evaluate a determinant of any order n*n.
Input would be the value of n and the determinant itself.The output is the value of the determinant.
😁

Replies

  • niraj.kumar
    niraj.kumar
    Dont get you can you please provide me an example wat actually you are asking for, as far as I know in program to evaluate the complexity you have 2 make changes in the code.Please correct me if I am wrong
  • Ashutosh_shukla
    Ashutosh_shukla
    You can be given any determinant as input say maximum order 10 x 10.
    You have to write the program to evaluate this determinant.

    Example:
    Input will be
    Order:4
    Actual determinant:
    8 1 0 0
    16 18 8 1
    0 5 16 18
    0 0 0 5

    Output will be value : 8640
  • Ashutosh_shukla
    Ashutosh_shukla
    I think no one tried it out. Here is my code Pleasse check this one out and if you find a better one tell me.
    //Program to evaluate determinant of any order
    #include
    #include
    void print(int a[10][10],int m,int n);
    int eval(int det[10][10],int n);
    void main()
    {
     int a[10][10],i,j,n;
     clrscr();
     cout<<"Enter the order of the matrix : ";
     cin>>n;
     cout<<"Enter the elements of the matrix : \n";
     for(i=0;i😁
                                        
  • pradeep_agrawal
    pradeep_agrawal
    Below is my piece of code for same.

    #include "stdio.h"
    
    
    #define MAX_MATRIX_ORDER 10
    
    
    void print_matrix(int matrix[MAX_MATRIX_ORDER][MAX_MATRIX_ORDER], int order) {
      int i = 0, j = 0;
      for(i = 0; i < order; i++) {
        for(j = 0; j < order; j++) {
          printf("%d ", matrix[i][j]);
        }
        printf("\n");
      }
    }
    
    
    long calculate_determinant(int matrix[MAX_MATRIX_ORDER][MAX_MATRIX_ORDER], int order) {
      int submatrix[MAX_MATRIX_ORDER][MAX_MATRIX_ORDER] = { 0 };
      int determinant = 0;
      int sign = 1;
      int i = 0, j = 0, k = 0;
    
      if(order == 1) {
        determinant = matrix[0][0];
      } else {
        for(i = 0; i < order; i++) {
          for(j = 0; j < (order - 1); j++) {
            for(k = 0; k < (order - 1); k++) {
              if(k < i) {
                submatrix[j][k] = matrix[j + 1][k];
              } else {
                submatrix[j][k] = matrix[j + 1][k + 1];
              }
            }
          }
          determinant += sign * matrix[0][i] * calculate_determinant(submatrix, order -1);
          sign = -sign;
        }
      }
    
      return determinant;
    }
    
    
    int main() {
      int matrix[MAX_MATRIX_ORDER][MAX_MATRIX_ORDER] = { 0 };
      int order = 0;
      long determinant = 0;
      int i = 0, j = 0;
    
      scanf("%d", &order);
      if(order > MAX_MATRIX_ORDER) {
        printf("Matrix order too high\n");
        return 0;
      } else if(order < 1) {
        printf("Invalid matrix order\n");
        return 0;
      }
    
      for(i = 0; i < order; i++) {
        for(j = 0; j < order; j++) {
          scanf("%d", &matrix[i][j]);
        }
      }
    
      printf("Matrix:\n");
      print_matrix(matrix, order);
    
      determinant = calculate_determinant(matrix, order);
      printf("Determinant: %d\n", determinant);
    
      return 0;
    }
    
    Compile the file with above code and run as:
    a.exe < input.txt > output.txt [on windows]
    a.out < input.txt > output.txt [on linux]

    Here,
    a.exe or a.out are the executables generated after compilation

    input.txt is the file containing input, e.g., if the matrix of order 4 is:
    8 1 0 0
    16 18 8 1
    0 5 16 18
    0 0 0 5
    Then input.txt will be
    4
    8 1 0 0
    16 18 8 1
    0 5 16 18
    0 0 0 5

    output.txt is the output file containing result, for given example output.txt will contain
    Matrix:
    8 1 0 0
    16 18 8 1
    0 5 16 18
    0 0 0 5
    Determinant: 8640

    Let me know if any item need clarification.

    -Pradeep

You are reading an archived discussion.

Related Posts

Hi Can any one tell me how to represent a Sparse Matrix using arrays. and also how to add two sparse matrices.😲
Hi, I am new to this and a warm hello to all. Looking forward to having a great time. Thanks. A ===============
Hi, Have some very interesting opportunities with a major product company here in Hyderabad, India. The company, founded in 1981, with 90 offices worldwide and more than 1600 employees and...
Hiii all, Do anyone have codes to generate Direct Sequence Spread Spectrum blocks? I mean the matlab codes to generate DSSS blocks. Or any links where i can get or...
Hi all, I final year student, having problem with my final year project. Hope can get help from ur guys. I want to design the ‘Tx/Rx or Bluetooth’ systems. Which...