【嚴蔚敏】【數據結構(C語言版)】 求n的階乘


階乘函數為:   

 

 

使用遞歸即可求得。

 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 
 4 int Fact(int m){
 5     if(m==0) return 1;
 6     else return m*Fact(m-1);   //遞歸求階乘 
 7 }
 8 int main() {
 9     int n;
10     printf("請輸入n的值:"); 
11     scanf("%d",&n);
12     printf("%d的階乘為:%d",n,Fact(n));
13     system("PAUSE");
14     return 0;
15 }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM