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.