提交 e70113c0 编写于 作者: 每日一练社区's avatar 每日一练社区

update dailycode pipline data

上级 f17722dd
# 找出小于平均值的数。 # 找出小于平均值的数。
<p>从键盘输入一个正整数存入变量n中&#xff0c;再输入n个整数&#xff0c;然后找出所有小于平均值的数&#xff0c;并按输入顺序输出。 <p>从键盘输入一个正整数存入变量n中&#xff0c;再输入n个整数&#xff0c;然后找出所有小于平均值的数&#xff0c;并按输入顺序输出。</p>
 
 </p> 以下程序实现了这一功能,请你补全空白处内容:
```cpp
#include <stdio.h>
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 ## template
```cpp ```cpp
#include<stdio.h> #include <stdio.h>
int main() int main()
{ {
int i,n,sum=0,a[100]; int i, n, sum = 0, a[100];
float ave; float ave;
scanf("%d",&n); scanf("%d", &n);
for(i=0;i<n;i++){ for (i = 0; i < n; i++)
scanf("%d",&a[i]); {
sum+=a[i]; scanf("%d", &a[i]);
sum += a[i];
} }
ave=sum*1.0/n; ave = sum * 1.0 / n;
for(i=0;i<n;i++){ for (i = 0; i < n; i++)
if(a[i]<ave) {
printf("%d",a[i]); if (a[i] < ave)
printf("%d", a[i]);
} }
return 0; return 0;
} }
...@@ -29,7 +52,8 @@ int main() ...@@ -29,7 +52,8 @@ int main()
## 答案 ## 答案
```cpp ```cpp
if (a[i] < ave)
printf("%d", a[i]);
``` ```
## 选项 ## 选项
...@@ -37,17 +61,20 @@ int main() ...@@ -37,17 +61,20 @@ int main()
### A ### A
```cpp ```cpp
if (a[i] <= ave)
printf("%d", a[i]);
``` ```
### B ### B
```cpp ```cpp
if (a[i] > ave)
printf("%d", a[i]);
``` ```
### C ### C
```cpp ```cpp
if (a[i] >= ave)
printf("%d", a[i]);
``` ```
\ No newline at end of file
...@@ -6,49 +6,51 @@ ...@@ -6,49 +6,51 @@
```cpp ```cpp
#include <stdio.h> #include <stdio.h>
int fun(int n,int *x,int *y) int fun(int n, int *x, int *y)
{ {
int sum = 0,i; int sum = 0, i;
int size = 0; int size = 0;
int dd = 1; int dd = 1;
for (i = 1; i <= (*x);i++) for (i = 1; i <= (*x); i++)
{ {
sum += (2*i-1); sum += (2 * i - 1);
} }
if (sum == n) if (sum == n)
{ {
*y = 2*(*x) -1; *y = 2 * (*x) - 1;
return (*x); return (*x);
}else if (sum > n) }
else if (sum > n)
{ {
(*y) = n - (sum - (2 * (*x) -1)); (*y) = n - (sum - (2 * (*x) - 1));
size = 2* (*x) -1; size = 2 * (*x) - 1;
dd = (*x); dd = (*x);
for (i = 2; i <= (*y);i++) for (i = 2; i <= (*y); i++)
{ {
if(i <= (*x)) if (i <= (*x))
dd *= 2; dd *= 2;
else else
dd /= 2; dd /= 2;
} }
return dd; return dd;
}else }
else
{ {
(*x)++; (*x)++;
return fun(n,x,y); return fun(n, x, y);
} }
} }
int main() int main()
{ {
int n; int n;
int row = 1,col = 0; int row = 1, col = 0;
int val; int val;
row = 1; row = 1;
col = 0; col = 0;
printf("请输入n:"); printf("请输入n:");
scanf("%d",&n); scanf("%d", &n);
val = fun(n,&row,&col); val = fun(n, &row, &col);
printf("第%d项是:%d\n",n,val); printf("第%d项是:%d\n", n, val);
return 0; return 0;
} }
``` ```
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册