Implementation of simple physics problems in C Language
Problem: A ball falls freely from a 100-meter-tall place. After each landing, it jumps back to half of the original height, then drops, and then rebounds. Ask how many meters a total of 10th landing times, how high the rebound of 10th times. Code implementation:
# Include <stdio. h> float s_n (float h, const int n, float s) // defines the number of meters passed by n times. {int I = 0; while (I <n) {s = s + h; h = h/2; I ++;} return s;} float last_h (float h, const int n) // defines how high the nth bounce is. {int I = 0; while (I <n) {h = h/2; I ++;} return h ;} int main () {float s = 0.0; int n = 0; float hn = 0.0; float h = 100.0; printf ("Enter the number of times :"); scanf ("% d", & n); hn = last_h (h, n); s = s_n (h, n, s ); printf ("hn = % f \ n", hn); printf ("s = % f \ n", s); return 0 ;}