返回列表 發帖
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int print(int i,int result)
  5. {
  6.     int totle=result;
  7.    if(i>0)
  8.    {
  9.    totle = totle*i;
  10.    i--;
  11.    return print(i,totle);
  12.    }
  13.    else
  14.    {return totle;
  15.    }
  16. }
  17. int main()
  18. {
  19.       int i=0;
  20.     cout<<"您的數是:";
  21.     cin>>i;
  22.     cout<<print(i,1)<<endl;
  23.      system("pause");
  24.      return 0;
  25. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int f(int n)
  5. {
  6.     if(n==1)
  7.      return 1;
  8.     else
  9.      return n*f(n-1);
  10. }
  11. int main()
  12. {
  13.      int w;
  14.      cout<<"接成運算";
  15.      cin>>w;
  16.      cout<<f(w)<<"!"<<endl;        

  17.     system("pause");
  18.     return 0;
  19. }
複製代碼

TOP

返回列表