Question

Write a progran1 that asks the user to enter a U.S. dollar amount and tben shows...

Write a progran1 that asks the user to enter a U.S. dollar amount and tben shows how to pay that amount using the smallest number of $20, $IO. $5, and $1 biJ ls?

Homework Answers

Answer #1

for this problem the greedy strategy is optimal,

"pay as much with the highest denomination available"

for example $56 are paid with 2 $20 , 1 $10 and 1 $5 and 1 $1 bill.

the c code is:


#include <stdio.h>

int main() {
    int twenty=0;
    int tens=0;
    int fives=0;
    int ones=0;
    int amount;
    printf("Enter an integer amount:\n");
    scanf("%d",&amount);
    while(amount>=20){
        amount=amount-20;
        twenty++;
    }
     while(amount>=10){
        amount=amount-10;
        tens++;
    }
     while(amount>=5){
        amount=amount-5;
        fives++;
    }
     while(amount>0){
        amount=amount-1;
        ones++;
    }
    printf("Number of bills required is:%d ",twenty+tens+fives+ones);
    return 0;
}
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a program that asks the user to enter a U.S. dollar amount and then shows...
Write a program that asks the user to enter a U.S. dollar amount and then shows how to pay that amount using the smallest number of $100, $20, $10, and $5 bills. Following are a few test cases for your program: Enter the amount for withdrawal: 125 Please collect your bills as follows: $100: 1 $20: 1 $5: 1 Enter the amount for withdrawal: 94 The amount cannot be withdrawn. Note: Be sure to use integer values throughout, not floating...
WRITE it in Python! how to Write a method named smallest largest that asks the user...
WRITE it in Python! how to Write a method named smallest largest that asks the user to enter numbers, then prints the smallest and largest of all the numbers typed in by the user. You may assume the user enters a valid number greater than 0 for the number of numbers to read. Here is an example dialogue: How many numbers do you want to enter? 4 Number 1: 5 Number 2: 11 Number 3: -2 Number 4: 3 Smallest...
Q :     Write a C++ program that asks the user to enter three integers and...
Q :     Write a C++ program that asks the user to enter three integers and then displays the largest one. Example : if the user enter ( 7, 2 ,5) the largest number will be 7 Or if user enter ( 2 , 5 , 7 ) the largest number will be 7 Or if user enter ( 7, 5 ,2) the largest number will be 7 In general it does not matter the order of the entered numbers...
write a program that asks the User to enter a letter, then asks the user to...
write a program that asks the User to enter a letter, then asks the user to enter a sentence. the program will then print out how many time that letter occurred in the sentence. in C Language
write a C++ program that asks the user to enter 4 integer numbers then use if...
write a C++ program that asks the user to enter 4 integer numbers then use if ….. elseif ….. elseif ….. else to find the smallest number then display it.
in .java Write a program that asks the user to enter 3 grades and computes the...
in .java Write a program that asks the user to enter 3 grades and computes the minimum and the maximum of those 3 grades and prints it. Hint: Use the Math.min() and Math.max() methods. This program will compute the smallest and highest of 3 grades entered by the user. Enter 3 grades separated by a space: 100 85.3 90.5 Smallest: 85.3 Highest: 100.0 Bye
in c++ Write a C++ program that asks the user to enter an integer number and...
in c++ Write a C++ program that asks the user to enter an integer number and prints it back "vertically" to the screen. Use recursion in your solution. As an example of how the program will work: Please enter an integer: 12345 The integer you entered will print vertically as: 1 2 3 4 5
1)Write a program that asks a user for a number. If (and only if) the number...
1)Write a program that asks a user for a number. If (and only if) the number is greater than zero print “The number is valid” 2)Write a program that asks a user for a grade. If (and only if) the grade is greater than zero and less than 101, print “The grade is valid” 3)Write a program that asks a user how many widgets they want to buy and prints out what the user should pay. Widgets costs 10 dollars....
Write a program that asks the user to enter an odd number and prints out a...
Write a program that asks the user to enter an odd number and prints out a triangle pattern. For example, if the user enters 5, the output is note: There is one space between the numbers in each line 1 3 5 1 3 1 If the user enters 9 the output is: 1 3 5 7 9 1 3 5 7 1 3 5 1 3 1 program language: C++
Write a program that asks the user to enter the number of days and then converts...
Write a program that asks the user to enter the number of days and then converts that value to weeks and days. For example, it would convert 18 days to 2 weeks, 4 days. Display results in the following format: 18 days are 2 weeks, 4 days. Use a while loop to allow the user to repeatedly enter day values; terminate the loop when the user enters a nonpositive value, such as 0 or -20.
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT