Summary and recursive learning to use recursive n! (Attached on n! Array realization)

 First, the concept of recursion and its role in
the program that calls itself recursively called programming skills (recursion). As a kind of recursive algorithm widely used programming languages. A procedure or function calls itself directly or indirectly in a way, it is usually a large, complex problem into a layer similar to the original problem to solve smaller problems in its definition or description, Recursion only requiring less program can describe the problem-solving process is repeated calculation needed, greatly reducing the code size. Recursive infinite set of capabilities that with limited statement to define object. Generally, recursive need to have the boundary conditions, recursive and recursive return of the advance period. When the boundary condition is not satisfied, recursive forward; when the boundary conditions are met, the recursive return.

 


Achieve n! There are many ways to count the amount of Fibonacci Fibonacci column, in order to introduce this recursive method, so as an example, the use of recursive binary translation. The following recursive converts the binary code (Note given in detail) are given here not explained in detail.

Second, the recursive n!

#include <stdio.h> // recursive function realized int the Fact ( int n-) 
{ IF (== n- 0 ) 
    {    // when n == 0 return 1 i.e. 0! . 1 = return . 1 ;   
    } the else 
    { return n-* the Fact (N- . 1 ); // recursive formula     } 
} int main ()   // main function {
     int n-, SUM; 
    Scanf ( " % D " , & n-);     // input     
    SUM = the Fact (n-); 
    the printf ( "
 


    
         
    
        

 



    D% " , SUM);   // output 
    return  0 ; 
}

Three, n! Array implementation code (not too much to explain)

#include<stdio.h>
 
int main()
{
    int n;
    scanf("%d",&n);
    int t=n,fact=1; //当n==0时fact=1
    while(n>1)
    {
        fact*=n--;
    
    }
    printf("%d\n",fact);
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/everrrr/p/10990365.html