- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures

- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces

# Maximize big when both big and small can be exchanged in C++

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

## Approach used in the below program is as follows

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.

## Example

#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; }

## Output

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

- Related Articles
- Taxes on Markets, Traders Big and Small
- Competitive Advantage of Small Businesses Over Big Brands
- Big Omega (Ω) and Big Thera (θ) Notation
- How can reverberations in a big hall or auditorium be reduced?
- Explain why, big boulders can be moved easily by flood.
- Why big tag is not in HTML5 while small tag exists?
- How to convert a small brand into a big one?
- Arrange the following in a food chain :Fish, Algae, Small animals, Big Fish
- Big Numbers in Python
- Big Endian and Little Endian
- What Will Be the Next Big Thing in Digital Marketing?
- Prime factors of a big number in C++
- C++ Program for quotient and remainder of big number
- Difference between IoT and Big Data
- Difference between Big Data and Hadoop