#include <iostream>
#include <iomanip>
long double fat(int n)
{
long double result = 1;
if (n < 0)
{
std::cout << "数字非法";
exit(1);
}
if (n == 0)
{
result = 1;
}
if (n > 0)
{
for (size_t i = 1; i < n + 1; i++)
{
result *= i;
}
}
return result;
}
int main(int argc, char const *argv[])
{
int a = 0;
while (a != 50)
{
std::cin >> a;
std::cout << std::fixed<<std::setprecision(0)<< fat(a) << std::endl;
std::cout<<std::endl;
}
return 0;
}
---------------------------------------------------------------------------------------------
Microsoft Windows [版本 10.0.16299.1087]
(c) 2017 Microsoft Corporation。保留所有权利。
E:\Users\86184\Documents\Code>c:\Users\86184\.vscode\extensions\ms-vscode.cpptools-0.26.0\debugAdapters\bin\WindowsDebugLauncher.exe --stdin=Microsoft-MIEngine-In-neu43l3z.f4x --stdout=Microsoft-MIEngine-Out-0iqgw4w3.i2l --stderr=Microsoft-MIEngine-Error-orbrm5v5.2k3 --pid=Microsoft-MIEngine-Pid-w0g1l25q.djc "--dbgExe=E:\My Program\MinGW\bin\gdb.exe" --interpreter=mi
0
1
1
1
5
120
50
30414093201713378039796484017234741538658648106343392576177963008
E:\Users\86184\Documents\Code> |