#include<iostream>
using namespace std;
int main()
{double n,t=0,x=2,s=0;//n是目标距离,t是步数,x是每一步的距离
cin>>n;
do{
s+=x;
t++;
x*=0.98;}
while(s<n);
cout<<t;
return 0;
}
计数问题
于 2018-01-24 00:03:54 首次发布
#include<iostream>
using namespace std;
int main()
{double n,t=0,x=2,s=0;//n是目标距离,t是步数,x是每一步的距离
cin>>n;
do{
s+=x;
t++;
x*=0.98;}
while(s<n);
cout<<t;
return 0;
}