题解 | #求小球落地5次后所经历的路程和第5次反弹的高度#
求小球落地5次后所经历的路程和第5次反弹的高度
https://www.nowcoder.com/practice/2f6f9339d151410583459847ecc98446
#include <iostream>
// #include <iomanip>
#include <bits/stdc++.h>
using namespace std;
int main(){
float s = 0, h;
cin >> h;
int n = 5; //n为落地次数
int m = 6; //保留6位数的小数
for (int i = 0; i < n; ++i){
s += h;
h /= 2;
if (i == n - 1){
// cout << fixed << setprecision(m) << s << endl << fixed << setprecision(m) << h;m为小数点后位数
cout << setprecision(m) << s << endl << setprecision(m) << h;//m位有效数字,即小数点前后共m位
}
s += h;
}
return 0;
}
#23届找工作求助阵地##我的实习求职记录##14天打卡计划##零基础学习C++#
查看10道真题和解析