Apple and bug problems C ++ and Apple bug problems C

Source: Internet
Author: User

Apple and bug problems C ++ and Apple bug problems C

If you need to reprint, please indicate the source: http://www.cnblogs.com/wongyi/p/8205305.html

Recently, I have been giving some questions to the students. I thought it would be more concentrated to write the questions.

The problem is as follows:

Apple and bugs:

You bought a box of n apples. Unfortunately, when you buy a box, the box is mixed into a worm. The worm can eat an apple every x hours, assume that the worm will not eat the other one before eating an apple, how many complete good apples will you have after y hours?

Example input: 10 4 9 (indicates a box of 10 apples, one for 4 hours, and a few for 9 hours ?)

Sample output: 7

Code implementation: It should be noted that the value is rounded up, and the default value is rounded down.

The Code is as follows:

# Include <iostream> # include <math. h> using namespace std;/* run this program using the console pauser or add your own getch, system ("pause") or input loop */int main (int argc, char ** argv) {double x, y, n; cin> x> y> n; cout <ceil (y/x) <endl; cout <floor (y/x) <endl; cout <n-ceil (y/x); return 0 ;}

If you have any questions, please leave a message.

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.