C actual combat exercise topic 26 – finding factorial by recursion

Time:2020-9-26

Title:Use recursive method to find 5!.

Program analysis:Recursive formula: FN = FN_ 1*4!

example:

#include 
  
 int main()
 {
     int i;
     int fact(int);
     for(i=0;i<6;i++){
         printf("%d!=%d\n",i,fact(i));
     }
 }
 int fact(int j)
 {
     int sum;
     if(j==0){
         sum=1;
     } else {
         sum=j*fact(j-1);
     }
     return sum;
 }

The output results of the above examples are as follows:

0!=1
1!=1
2!=2
3!=6
4!=24
5!=120

Thank you for your reading, please feel with your heart! Hope to help you who love learning!! Sharing is also a kind of happiness!!! Please relay…

Click to view the original text, thank you!