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)

Source: Internet
Author: User

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;
} 


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.