C++求n的阶乘!

要简单点的~能运行出来的~谢谢
2024-11-30 12:43:57
推荐回答(2个)
回答1:

#include
using namespace std;
int main(){
unsigned long long n,m=1;
cin>>n;
for(int i=1;i<=n;i++){
m=m*i;
}
cout< return 0;
}

回答2:

#include
using namespace std;
int main(){

unsigned int n;
unsigned long long factorial = 1;

cout << "输入一个整数: ";
cin >> n;

for(int i = 1; i <=n; ++i)

{

factorial *= i;
}

cout << n << " 的阶乘为:"<< " = " << factorial;

return 0;
}