Implementation of simple physics problems in C Language

Source: Internet
Author: User

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

 

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.