题目描述
一球从M米高度自由下落,每次落地后返回原高度的一半,再落下。 它在第N次落地时反弹多高?共经过多少米? 保留两位小数
输入
M N
输出
它在第N次落地时反弹多高?共经过多少米? 保留两位小数,空格隔开,放在一行
样例输入
1000 5
样例输出
31.25 2875.00
#include "stdio.h" int main(int argc, char const *argv[]) { int M, N, i; float last_heigt, total = 0; scanf("%d%d", &M, &N); last_heigt = (float)M; for(i = 0; i < N; i++) { if(i == 0) //第一次落地 total = (float)M; else total += last_heigt * 2; last_heigt = last_heigt / 2; } printf("%.2f %.2f ", last_heigt, total); return 0; }