📜  程序从给定比率中查找每种类型的硬币数量

📅  最后修改于: 2021-04-24 15:25:24             🧑  作者: Mango

给出袋子中卢比的总数和硬币的比例。袋子中的X,Y,Z比率仅为1卢比,50帕斯,25帕斯硬币。任务是确定1个Rs硬币,50个Paise硬币和25个Paise硬币的数量,以便在所有这些总和之后,再次得到给定的总卢比。
例子:

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

方法:

下面是上述方法的实现:

C++
// C++ implementation of above approach
#include 
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;
}


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.


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


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


PHP


Javascript


输出:
1 rupess coins = 600
50 paisa coins = 1200
25 paisa coins = 2400