//=================================== //EX0210.cpp //球的高度 //=================================== #include<iostream> using namespace std; //----------------------------------- int main() { double sum=100, height=100; for(int i=1; i<10; i++, height/=2) sum += height; cout<<sum<<"\n"<<height/2<<"n"; }//==================================
#include <iostream> using namespace std; int main() { double sum(0); double init(100); for (int i = 0; i < 10; i++) { sum += init + (init / 2); init /= 2; if (i == 9) { cout << (init / 2) << endl; } } cout << sum << endl; ; }
count = 0 height = 100 meter = 0 while count < 10: meter += height # 下落 height /= 2 meter += height # 反弹 count += 1 print(meter, height)
这道题你会答吗?花几分钟告诉大家答案吧!
扫描二维码,关注牛客网
下载牛客APP,随时随地刷题