A typical C language programming language (c18), with a ball falling from a 100-meter height, jumps back to half of the original height after each landing, and the Language Programming Language (c18)
C language, c18, classic
/ * [Program 18] c18
* Title: A ball falls freely from a height of 100 meters. After each landing, it bounces back to half of its original height. If it falls again, find it at
How many meters did you pass when you landed for the nth time? How high will it bounce after landing?
* Program analysis: The height of the n-th bounce is half of the previous bounce. When counting how many meters passes, it does not count the height of the bounce * /
#include
int main (int argc, char * argv [])
{
double height = 100;
double half = height / 2;
Ranch
int i;
printf ("Please enter the number of landing:");
scanf ("% d", & i);
Ranch
if (i == 1) ()
else
{
int n;
for (n = 2; n <= i; n ++)
{
height + = half * 2; // the number of meters passed by the nth landing
half = half / 2; // height of the n-th bounce
}
}
Ranch
printf ("The% d landing, passed% lf meters \ n", i, height);
printf ("The% d landing will bounce% lf meters \ n", i, half);
Ranch
return 0;
}