CoderCatt @ 2021-11-14 10:25:01
#include<stdio.h>
int main()
{
int i, a[11]={0}, b;
for (i = 0; i < 10; i++) {
scanf("%d ", &a[i]);//苹果高度
}
scanf("%d", &b);//人高度
int c = 1, t=1;
for (i = 0; i < 10; i++) {
if ((b + 30) >= a[i])//人高过苹果
t = c++;//摘苹果数
}
printf("%d", t);
}
by Mathlover__CQYZ @ 2021-11-14 10:40:25
互关后领取
#include<iostream>
#include<cmath>
using namespace std;
int a[15];
int main()
{
int b,B,A;
for(int i=1;i<=10;i++)
cin>>a[i];
cin>>b;
B=b+30;
int c=0;
for(int i=1;i<=10;i++)
{
if(a[i]<=B)
c++ ;
}
cout<<c;
return 0;
}
by wjj255 @ 2021-11-14 10:44:55
这样
#include<stdio.h>
int main()
{
int i, a[11]={0}, b;
for (i = 0; i < 10; i++) {
scanf("%d ", &a[i]);
}
scanf("%d", &b);
int t=0;
for (i = 0; i < 10; i++) {
if ((b + 30) >= a[i])
t++;
}
printf("%d",t);
}
by CoderCatt @ 2021-11-14 11:29:56
@wjj255 你好,能说说我的错误是什么吗?
by Mr_ll @ 2021-11-14 11:34:46
@CoderCatt 有没有可能一个苹果也摘不到呢
by Mr_ll @ 2021-11-14 11:38:29
int c = 1, t=1;
改成试试
int c = 1, t=0;
by wjj255 @ 2021-11-14 12:06:37
@CoderCatt 1.变量c没有用就删掉
2.累加量t初始值应为0;
by CoderCatt @ 2021-11-14 13:50:08
@wjj255 明白了,谢谢