From e70113c0cf6eb83363102121b8b70631be63ff3b Mon Sep 17 00:00:00 2001 From: zhangzc Date: Tue, 30 Nov 2021 10:56:17 +0800 Subject: [PATCH] update dailycode pipline data --- .../1.cpp/29.exercises/solution.md" | 69 +++++++++++----- .../1.cpp/30.exercises/solution.md" | 82 ++++++++++--------- 2 files changed, 90 insertions(+), 61 deletions(-) diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/29.exercises/solution.md" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/29.exercises/solution.md" index aa266713a..250da8091 100644 --- "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/29.exercises/solution.md" +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/29.exercises/solution.md" @@ -1,35 +1,59 @@ # 找出小于平均值的数。 -

从键盘输入一个正整数存入变量n中,再输入n个整数,然后找出所有小于平均值的数,并按输入顺序输出。 -  - 

+

从键盘输入一个正整数存入变量n中,再输入n个整数,然后找出所有小于平均值的数,并按输入顺序输出。

+ +以下程序实现了这一功能,请你补全空白处内容: + +```cpp +#include +int main() +{ + int i, n, sum = 0, a[100]; + float ave; + scanf("%d", &n); + for (i = 0; i < n; i++) + { + scanf("%d", &a[i]); + sum += a[i]; + } + ave = sum * 1.0 / n; + for (i = 0; i < n; i++) + { + __________________ + } + return 0; +} +``` ## template ```cpp -#include +#include int main() { - int i,n,sum=0,a[100]; - float ave; - scanf("%d",&n); - for(i=0;i ave) + printf("%d", a[i]); ``` ### C ```cpp - +if (a[i] >= ave) + printf("%d", a[i]); ``` \ No newline at end of file diff --git "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/30.exercises/solution.md" "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/30.exercises/solution.md" index f42ad049b..ac2091a6c 100644 --- "a/data/1.dailycode\345\210\235\351\230\266/1.cpp/30.exercises/solution.md" +++ "b/data/1.dailycode\345\210\235\351\230\266/1.cpp/30.exercises/solution.md" @@ -6,50 +6,52 @@ ```cpp #include -int fun(int n,int *x,int *y) +int fun(int n, int *x, int *y) { - int sum = 0,i; - int size = 0; - int dd = 1; - for (i = 1; i <= (*x);i++) - { - sum += (2*i-1); - } - if (sum == n) - { - *y = 2*(*x) -1; - return (*x); - }else if (sum > n) - { - (*y) = n - (sum - (2 * (*x) -1)); - size = 2* (*x) -1; - dd = (*x); - for (i = 2; i <= (*y);i++) - { - if(i <= (*x)) - dd *= 2; - else - dd /= 2; - } - return dd; - }else - { - (*x)++; - return fun(n,x,y); - } + int sum = 0, i; + int size = 0; + int dd = 1; + for (i = 1; i <= (*x); i++) + { + sum += (2 * i - 1); + } + if (sum == n) + { + *y = 2 * (*x) - 1; + return (*x); + } + else if (sum > n) + { + (*y) = n - (sum - (2 * (*x) - 1)); + size = 2 * (*x) - 1; + dd = (*x); + for (i = 2; i <= (*y); i++) + { + if (i <= (*x)) + dd *= 2; + else + dd /= 2; + } + return dd; + } + else + { + (*x)++; + return fun(n, x, y); + } } int main() { - int n; - int row = 1,col = 0; - int val; - row = 1; - col = 0; - printf("请输入n:"); - scanf("%d",&n); - val = fun(n,&row,&col); - printf("第%d项是:%d\n",n,val); - return 0; + int n; + int row = 1, col = 0; + int val; + row = 1; + col = 0; + printf("请输入n:"); + scanf("%d", &n); + val = fun(n, &row, &col); + printf("第%d项是:%d\n", n, val); + return 0; } ``` -- GitLab