- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

We are given a big object let’s say, ‘a’ and a small object let’s say, ‘b’. The choices for the object ‘a’ and ‘b’ depend upon the user. In the example below, we are taking objects to be toys which are big as well as small as per the size characteristics. The task is to calculate the maximum number of big toys that can be achieved by giving the small toys in return.

**Input** − big_toys = 8, small_toys = 20, a = 6, b = 4

**Output** − Maximize big when both big and small can be exchanged are − 11

**Explanation** − Maximum number of big toys that can be bought using small toys i.e. 20 are 11 in number

**Input** − big_toys = 3, small_toys = 10, a = 4, b = 2

**Output** − Maximize big when both big and small can be exchanged are: 5

**Explanation** − Maximum number of big toys that can be bought using small toys i.e. 10 are 5 in number

Input the total number of big toys and small toys. Also, take ‘a’ as the total of big toys that can be exchanged in return of small toys and ‘b’ as the total of small toys that can be exchanged in return of big toys.

If a < b then set small toys to be the sum of total number of small toys available with the b * total number of big toys available and set count of big toys as 0.

Now, set big toys to be the sum of the total number of big toys available with the small toys divided by a.

Return the total of big toys as we need the maximum of big toys that can be exchanged in return of small toys.

Print the result.

#include <iostream> using namespace std; int maximum(int big_toys, int small_toys,int a, int b){ if (a < b){ small_toys += b * big_toys; big_toys = 0; } big_toys += (small_toys / a); return big_toys; } int main(){ int big_toys = 8, small_toys = 20; int a = 6, b = 4; cout<<"Maximize big when both big and small can be exchanged are:"<<maximum(big_toys, small_toys, a, b); return 0; }

Maximize big when both big and small can be exchanged are: 11

- Related Questions & Answers
- Big Omega (Ω) and Big Thera (θ) Notation
- How to convert a small brand into a big one?
- Big Endian and Little Endian
- Big Numbers in Python
- Big Oh Notation (O)
- What is big data?
- C++ Program for quotient and remainder of big number
- Difference between Data Mining and Big Data?
- Can a C++ variable be both const and volatile?
- Prime factors of a big number in C++
- HTML <big> Tag
- The magnitude of big data
- How IoT impacts Big Data
- Difference between Big-O and Little-O Notation
- Why <big> is not in HTML 5 Tag list while <small> is?

Advertisements