#include <stdio.h> void foo( double h, unsigned n ) { printf( "起始%g米,第%u此落地,经过米数:%.4f,反弹高度%.4f\n", h, n, (3-4.0/(1u<<n))*h, h/(1u<<n) ); } int main( void ) { foo( 64, 1 ); foo( 64, 2 ); foo( 64, 3 ); foo( 64, 4 ); foo( 64, 5 ); }
#include <stdio.h> int main(void) { double h; int n; double s = 0; int i = 0; printf("h = "); scanf("%lf",&h); printf("n = "); scanf("%d",&n); i = h; while(n--) { s += i; h = h / 2; i = 2 * h; printf("s = %lf, h = %lf\n", s, h); } return 0; }