C-Language for determinant values

Source: Internet
Author: User

#include"stdafx.h"#include<stdio.h>#include<stdlib.h>#include<windows.h>#defineNUM 3intFun (intNintA[num][num]);/*function Declaration*/intMain () {inti =0, j =0;/*i,j represents rows and columns, respectively*/    inta[3][3] = { { -,6,2},{6,3,3},{5,9,8} };/*Defining determinant*/printf ("%d\n", Fun (NUM, a)); System ("Pause"); return 0;}/*The following is a recursive function for calculating determinant values*/intFun (intNintA[num][num]) {    Static intB[num][num] = {{0} };/*Define array B and initialize*/    inti =0, j =0, sum =0;/*i,j is row and column, sum is the value of the determinant*/    intx =0, C =0, p =0;/*use X to determine the addition and subtraction, c,p as the intermediate variable*/    if(n = =1)        returna[0][0];  for(i =0; I < n; i++)/*here Cycle implementation will cofactor type in array b*/    {         for(c =0; C < n-1; C++)        {             for(j =0; J < N-1; J + +)            {                if(C < i) {/*use C to determine how each line moves*/P=0;/*when P=0, the determinant only shifts to the left, that is, the number of the corresponding first column is eliminated .*/                }                Else{/*Otherwise, the determinant shifts left and then moves up.*/P=1; } B[c][j]= a[c + P][j +1]; }        }        ifI2==0) {/*I+j (at this time j=0, so only i) is even, the addition budget*/x=1; }        Else{/*I+j is an odd, subtraction operation*/x= (-1); } Sum+ = a[i][0] * Fun (N-1, b) * x;/*calculate the value of a determinant*/    }    returnSum/*returns the value*/}

C-Language for determinant values

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.