From adb07f27c52be5a7012f0bbba4ad2ecf00c8c1d4 Mon Sep 17 00:00:00 2001 From: smallkun Date: Tue, 18 Mar 2025 08:37:39 +0800 Subject: [PATCH] Auto commit --- 2207/C语言同步练习源码/4.函数-3.c | 30 ++++++++++++++++++++++++++++++ 2207/C语言同步练习答案.md | 30 ++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 2207/C语言同步练习源码/4.函数-3.c diff --git a/2207/C语言同步练习源码/4.函数-3.c b/2207/C语言同步练习源码/4.函数-3.c new file mode 100644 index 0000000..3056c8f --- /dev/null +++ b/2207/C语言同步练习源码/4.函数-3.c @@ -0,0 +1,30 @@ +#include + +//ݴη +int power(int n){ + int s = 1, i; + for(i=1;i<=n;i++){ + s *= 2; + } + return s; +} +//׳ +int factorial(int n){ + int s = 1, i; + for(i=1;i<=n;i++){//1~n + s*=i; + } + return s; +} + +int main(){ + int n, i, s = 0; + scanf("%d", &n); + for(i=1;i<=n;i++){ + s += power(i) * factorial(i); + } + printf("%d\n", s); + + return 0; +} + diff --git a/2207/C语言同步练习答案.md b/2207/C语言同步练习答案.md index 2cc3d32..b70bd79 100644 --- a/2207/C语言同步练习答案.md +++ b/2207/C语言同步练习答案.md @@ -702,6 +702,36 @@ int main(){ ![image-20250227231154429](https://yp.smallkun.cn/markdown/image-20250227231154429.png!compress) ```c +#include + +//幂次方 +int power(int n){ + int s = 1, i; + for(i=1;i<=n;i++){ + s *= 2; + } + return s; +} +//阶乘 +int factorial(int n){ + int s = 1, i; + for(i=1;i<=n;i++){//1~n + s*=i; + } + return s; +} + +int main(){ + int n, i, s = 0; + scanf("%d", &n); + for(i=1;i<=n;i++){ + s += power(i) * factorial(i); + } + printf("%d\n", s); + + return 0; +} + ```