Given the total number of Rupees in a bag and the ratio of coins. The bag contains only 1 Rs, 50 paise, 25 paise coins in X, Y, Z, ratio. The task is to determine the number of 1 Rs coins, 50 Paise coins, and 25 paise coins So that after summation of all these we again get the total rupees given.

**Examples:**

Input: totalRupees = 1800, X = 1, Y = 2, Z = 4 Output: 1 rupees coins = 600 50 paisa coins = 1200 25 paisa coins = 2400 Input: totalRupees = 2500, X = 2, Y = 4, Z = 2 Output: 1 rupees coins = 555 50 paisa coins = 1110 25 paisa coins = 2220

**Approach:**

Let the ratio in which 1 Rs, 50 paise and 25 paise coin is divided is 1:2:4

Now,

1 Rs coins in a bag is 1x.

50 paise coins in a bag is 2x.

25 paise coins in a bag is 4x.Now convert these paise into Rupees.

So,

x coins of 1 Rs each, the total value is x rupees.

2x coins of 50 paise i.e (1 / 2) rupees each, the total value is x rupees.

4x coins of 25 paise i.e (1 / 4) rupees each, the total is x rupees.

Therefore,

3x = 1800

x = 6001 rupess coins = 600 * 1 = 600

50 paisa coins = 600 * 2 = 1200

25 paisa coins = 600 * 4 = 2400

Below is the implementation of the above approach:

## C++

`// C++ implementation of above approach ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `// function to calculate coin. ` `int` `coin(` `int` `totalRupees, ` `int` `X, ` `int` `Y, ` `int` `Z) ` `{ ` ` ` ` ` `float` `one = 0, fifty = 0, twentyfive = 0, ` ` ` `result = 0, total = 0; ` ` ` ` ` `// Converting each of them in rupees. ` ` ` `// As we are given totalRupees = 1800 ` ` ` `one = X * 1; ` ` ` `fifty = ((Y * 1) / 2.0); ` ` ` `twentyfive = ((Z * 1) / 4.0); ` ` ` ` ` `total = one + fifty + twentyfive; ` ` ` ` ` `result = ((totalRupees) / total); ` ` ` ` ` `return` `result; ` `} ` ` ` `// Driver code ` `int` `main() ` `{ ` ` ` `int` `totalRupees = 1800; ` ` ` `int` `X = 1, Y = 2, Z = 4; ` ` ` ` ` `int` `Rupees = coin(totalRupees, X, Y, Z); ` ` ` ` ` `cout << ` `"1 rupess coins = "` `<< Rupees * 1 << endl; ` ` ` `cout << ` `"50 paisa coins = "` `<< Rupees * 2 << endl; ` ` ` `cout << ` `"25 paisa coins = "` `<< Rupees * 4 << endl; ` ` ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java implementation of above approach ` ` ` `import` `java.io.*; ` ` ` `class` `GFG { ` ` ` `// function to calculate coin. ` ` ` `static` `int` `coin(` `int` `totalRupees, ` `int` `X, ` `int` `Y, ` `int` `Z) ` `{ ` ` ` ` ` `float` `one = ` `0` `, fifty = ` `0` `, twentyfive = ` `0` `, ` ` ` `result = ` `0` `, total = ` `0` `; ` ` ` ` ` `// Converting each of them in rupees. ` ` ` `// As we are given totalRupees = 1800 ` ` ` `one = X * ` `1` `; ` ` ` `fifty = ((Y * ` `1` `) / ` `2` `); ` ` ` `twentyfive = ((Z * ` `1` `) / ` `4` `); ` ` ` ` ` `total = one + fifty + twentyfive; ` ` ` ` ` `result = ((totalRupees) / total); ` ` ` ` ` `return` `(` `int` `)result; ` `} ` ` ` `// Driver code ` ` ` ` ` `public` `static` `void` `main (String[] args) { ` ` ` ` ` `int` `totalRupees = ` `1800` `; ` ` ` `int` `X = ` `1` `, Y = ` `2` `, Z = ` `4` `; ` ` ` ` ` `int` `Rupees = coin(totalRupees, X, Y, Z); ` ` ` ` ` `System.out.println( ` `"1 rupess coins = "` `+ Rupees * ` `1` `); ` ` ` `System.out.println( ` `"50 paisa coins = "` `+ Rupees * ` `2` `); ` ` ` `System.out.println( ` `"25 paisa coins = "` `+ Rupees * ` `4` `); ` ` ` `} ` `} ` `//This code is contributed by inder_verma. ` |

*chevron_right*

*filter_none*

## Python3

`# Python3 implementation of above approach ` ` ` `# function to calculate coin. ` `def` `coin(totalRupees, X, Y, Z): ` ` ` ` ` `# Converting each of them in rupees. ` ` ` `# As we are given totalRupees = 1800 ` ` ` `one ` `=` `X ` `*` `1` ` ` `fifty ` `=` `((Y ` `*` `1` `) ` `/` `2.0` `) ` ` ` `twentyfive ` `=` `((Z ` `*` `1` `) ` `/` `4.0` `) ` ` ` `total ` `=` `one ` `+` `fifty ` `+` `twentyfive ` ` ` `result ` `=` `((totalRupees) ` `/` `total) ` ` ` ` ` `return` `int` `(result) ` ` ` `# Driver code ` `if` `__name__` `=` `=` `'__main__'` `: ` ` ` `totalRupees ` `=` `1800` ` ` `X, Y, Z ` `=` `1` `, ` `2` `, ` `4` ` ` ` ` `Rupees ` `=` `coin(totalRupees, X, Y, Z) ` ` ` ` ` `print` `(` `"1 rupess coins = "` `, Rupees ` `*` `1` `) ` ` ` `print` `(` `"50 paisa coins = "` `, Rupees ` `*` `2` `) ` ` ` `print` `(` `"25 paisa coins = "` `, Rupees ` `*` `4` `) ` ` ` `# This code is contributed by ` `# Sanjit_Prasad ` |

*chevron_right*

*filter_none*

## C#

`// C# implementation of above approach ` `using` `System; ` ` ` `class` `GFG ` `{ ` ` ` `// function to calculate coin. ` `static` `int` `coin(` `int` `totalRupees, ` `int` `X, ` ` ` `int` `Y, ` `int` `Z) ` `{ ` ` ` ` ` `float` `one = 0, fifty = 0, twentyfive = 0, ` ` ` `result = 0, total = 0; ` ` ` ` ` `// Converting each of them in rupees. ` ` ` `// As we are given totalRupees = 1800 ` ` ` `one = X * 1; ` ` ` `fifty = ((Y * 1) / 2); ` ` ` `twentyfive = ((Z * 1) / 4); ` ` ` ` ` `total = one + fifty + twentyfive; ` ` ` ` ` `result = ((totalRupees) / total); ` ` ` ` ` `return` `(` `int` `)result; ` `} ` ` ` `// Driver code ` `public` `static` `void` `Main () ` `{ ` ` ` `int` `totalRupees = 1800; ` ` ` `int` `X = 1, Y = 2, Z = 4; ` ` ` ` ` `int` `Rupees = coin(totalRupees, X, Y, Z); ` ` ` ` ` `Console.WriteLine( ` `"1 rupess coins = "` `+ Rupees * 1); ` ` ` `Console.WriteLine( ` `"50 paisa coins = "` `+ Rupees * 2); ` ` ` `Console.WriteLine( ` `"25 paisa coins = "` `+ Rupees * 4); ` `} ` `} ` ` ` `// This code is contributed by inder_verma ` |

*chevron_right*

*filter_none*

## PHP

`<?php ` `// PHP implementation of above approach ` ` ` `//function to calculate coin ` `function` `coin(` `$totalRupees` `, ` `$X` `, ` `$Y` `, ` `$Z` `) ` `{ ` ` ` `$one` `= 0; ` ` ` `$fifty` `= 0; ` ` ` `$twentyfive` `= 0; ` ` ` `$result` `= 0; ` ` ` `$total` `= 0; ` ` ` ` ` `// Converting each of them in rupees. ` ` ` `// As we are given totalRupees = 1800 ` ` ` `$one` `= ` `$X` `* 1; ` ` ` `$fifty` `= ((` `$Y` `* 1) / 2.0); ` ` ` `$twentyfive` `= ((` `$Z` `* 1) / 4.0); ` ` ` ` ` `$total` `= ` `$one` `+ ` `$fifty` `+ ` `$twentyfive` `; ` ` ` ` ` `$result` `= ((` `$totalRupees` `) / ` `$total` `); ` ` ` ` ` `return` `$result` `; ` ` ` `} ` ` ` `// Driver Code ` `$totalRupees` `= 1800; ` `$X` `= 1; ` `$Y` `= 2; ` `$Z` `= 4; ` `$Rupees` `= coin(` `$totalRupees` `, ` `$X` `, ` `$Y` `, ` `$Z` `); ` `echo` `"1 rupess coins = "` `, ` `$Rupees` `* 1, ` `"\n"` `; ` `echo` `"50 paisa coins = "` `, ` `$Rupees` `* 2, ` `"\n"` `; ` `echo` `"25 paisa coins = "` `, ` `$Rupees` `* 4, ` `"\n"` `; ` ` ` `// This code is contributed ` `// by Shashank_Sharma. ` `?> ` |

*chevron_right*

*filter_none*

**Output:**

1 rupess coins = 600 50 paisa coins = 1200 25 paisa coins = 2400

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the **DSA Self Paced Course** at a student-friendly price and become industry ready.

## Recommended Posts:

- Sum of two numbers if the original ratio and new ratio obtained by adding a given number to each number is given
- Find the number which when added to the given ratio a : b, the ratio changes to c : d
- Ratio of mth and nth terms of an A. P. with given ratio of sums
- Maximum items that can be bought with the given type of coins
- Count of binary strings of length N having equal count of 0's and 1's and count of 1's ≥ count of 0's in each prefix substring
- Find minimum number of coins that make a given value
- Program to find the Sum of each Row and each Column of a Matrix
- Max count of unique ratio/fraction pairs in given arrays
- Program to find the common ratio of three numbers
- Find out the minimum number of coins required to pay total amount
- Find if it is possible to get a ratio from given ranges of costs and quantities
- Find amount to be added to achieve target ratio in a given mixture
- Find the ratio of LCM to GCD of a given Array
- Check if given coins can be used to pay a value of S
- Generate a combination of minimum coins that sums to a given value
- Count the number of rectangles such that ratio of sides lies in the range [a,b]
- Program to calculate the profit sharing ratio
- Find nth Fibonacci number using Golden ratio
- Find speed of man from speed of stream and ratio of time with up and down streams
- Find the ratio of number of elements in two Arrays from their individual and combined average

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.