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

update dailycode pipline data

上级 f17722dd
# 找出小于平均值的数。
<p>从键盘输入一个正整数存入变量n中&#xff0c;再输入n个整数&#xff0c;然后找出所有小于平均值的数&#xff0c;并按输入顺序输出。
 
 </p>
<p>从键盘输入一个正整数存入变量n中&#xff0c;再输入n个整数&#xff0c;然后找出所有小于平均值的数&#xff0c;并按输入顺序输出。</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
```cpp
#include<stdio.h>
#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++){
if(a[i]<ave)
printf("%d",a[i]);
}
return 0;
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++)
{
if (a[i] < ave)
printf("%d", a[i]);
}
return 0;
}
```
## 答案
```cpp
if (a[i] < ave)
printf("%d", a[i]);
```
## 选项
......@@ -37,17 +61,20 @@ int main()
### A
```cpp
if (a[i] <= ave)
printf("%d", a[i]);
```
### B
```cpp
if (a[i] > ave)
printf("%d", a[i]);
```
### C
```cpp
if (a[i] >= ave)
printf("%d", a[i]);
```
\ No newline at end of file
......@@ -6,50 +6,52 @@
```cpp
#include <stdio.h>
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;
}
```
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册