Suppose that nickels and pennies disappear from the currency system and we have
ID: 3784065 • Letter: S
Question
Suppose that nickels and pennies disappear from the currency system and we have only dimes and quarters. Obviously any product that costs 15 cents can not be exactly paid for using only dimes and quarters. Show the following using induction: For every n greaterthanorequalto 4, any product that costs 5n cents can be paid for exactly using only dimes and quarters" Equivalently, show that any integer of the form 5n (n greaterthanorequalto 4) can be written as 10_x + 25_y for some non-negative integers x and y.Explanation / Answer
In below program enter value of n and You can see for all value of n which is greater than 4 we can pay and we also got the value of x(number of dimes) and y(number of quarter) .
#include <iostream>
using namespace std;
int main()
{
int n,i;
int amt;
cout << "Enter value of n " << endl;
cin >> n;
for(i=4;i<n;i++)
{
amt=5*i;
int x=0,y=0;
if(amt %10 == 0 || amt %25 ==0)
{
if(amt % 10 ==0)
{
while(10*x != amt)
x++;
}
else if(amt%25 == 0)
{
while(25*y != amt)
y++;
}
cout << "Pay for n= " << i <<" and the amount is " << 5*i << " x = " << x << " y = " << y << endl;
}
else
{
while(amt > 5)
{
if(amt >= 25)
{
amt-=25;
y++;
if(amt %10 == 0)
{
while(10*x != amt)
x++;
amt=0;
}
}
else if(amt >=10)
{
amt-=10;
x++;
}
}
if(amt == 0)
cout << "Pay for n= " << i <<" and the amount is " << 5*i << " x = " << x << " y = " << y << endl;
else
cout << "can not pay n= " << i << " and the amount is " << 5*i << endl;
}
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.