小球自由落体(计算小球经过的路程和第N次弹起的高度)

假设 16m 计算第三次落地时反弹多高,共经过多少米

先了解大概要计算的内容
在这里插入图片描述

#include <stdio.h>

int main(void)
{
    
    
    float M, N;//M是落下的长度,N是落地的次数
    scanf("%f %f", &M, &N);
    float sn=M, hn=M/2;//第一次单独计算
    int i;
    for(i=2;i<=N;i++)
    {
    
    
        sn = sn + 2*hn;
        printf("%.2f\n",sn );
        hn = hn/2;
        printf("%.2f\n", hn);

    }

    printf("\n");

    printf("%.2f %.2f", hn, sn);
    return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_51676760/article/details/110327727
今日推荐