⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 p4_3.cpp

📁 相当丰富的C++源码
💻 CPP
字号:
/***********************************************
*   p4_3.cpp                                    *
* 函数的递归调用, 求n!                          *
************************************************/
#include<iostream>
using namespace std;
int fac(int n)
{
	int t;
    if(n==1) 
		t=1;
    else 
		t=n*fac(n-1);
    return (t);
}
void main()
{   const int max_n=12;  // int 类型数能表示的n!的最大的n
    int n;
    cout<<"Input a integer number:";
    cin>>n;
    if (n>=1&&n<=max_n)
		cout<<"Factorial of "<<n<<" is: "<<fac(n)<<endl;
	else
		cout<<"Invalid n."<<endl;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -