How many ways using UK coins (1,2,5,10,20,50,100,200) can you make 200p?
I just used loops for each coin type.. not very fast but does the trick..
______
static void Main(string[] args)
{
int c = 1; //2 dollar coin = one way
for (int p1 = 0; p1 < 201; p1++)
{
for (int p2 = 0; p2 < 201; p2 += 2)
{
for (int p5 = 0; p5 < 201; p5 += 5)
{
for (int p10 = 0; p10 < 201; p10 += 10)
{
for (int p20 = 0; p20 < 201; p20 += 20)
{
for (int p50 = 0; p50 < 201; p50 += 50)
{
for (int p100 = 0; p100 < 201; p100 += 100)
{
if (p1 + +p2 + p5 + p10 + p20 + p50 + p100 == 200)
{
c++;
}
}
}
}
}
}
}
}
Console.WriteLine(c);
Console.ReadLine();
}
No comments:
Post a Comment