Home  >  Article  >  System Tutorial  >  Implementing the apple and bug problem using C++

Implementing the apple and bug problem using C++

王林
王林forward
2024-04-14 09:20:21374browse

Implementing the apple and bug problem using C++

Recently, I am giving math Olympiad lessons to children. I read a few questions and thought it would be more concentrated to write them down. I will sort them out hahaha.

Questions are as follows:

Apples and worms:

You bought a box of n apples. Unfortunately, a bug got into the box when you finished buying. The bug can eat one apple every x hours. It is assumed that the bug will not leave before eating one apple. Eat another, so how many whole good apples do you have after y hours?

Sample input: 10 4 9 (meaning a box of 10 apples, if you eat one in 4 hours, how many will be complete after 9 hours?)

Sample output: 7

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

code show as below:

#include 
#include 

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

The above is the detailed content of Implementing the apple and bug problem using C++. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:linuxprobe.com. If there is any infringement, please contact admin@php.cn delete