diff --git a/day7/homework/oh2.cpp b/day7/homework/oh2.cpp new file mode 100644 index 0000000..7184e5a --- /dev/null +++ b/day7/homework/oh2.cpp @@ -0,0 +1,22 @@ +// 输入一个整数,输出它的阶乘。 +// 例如:输入5,输出120 +#include + +using namespace std; + +int main() +{ + int n; + int sum = 1; + cout << "请输入一个整数:"; + cin >> n; + + while (n) + { + sum *= n; + --n; + } + cout << sum << endl; + + return 0; +} \ No newline at end of file