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

Implementing the apple and bug problem using C++

王林
Release: 2024-04-14 09:20:21
forward
435 people have browsed it

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
Copy after login

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!

source:linuxprobe.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template