34.5k views
2 votes
Write a C program that asks the user to enter a US dollar amount and then shows how to pay that amount using the smallest number of $20,$10,$5 and $1 bills. Enter a dollar amount: 93

$20 bills: 4

$10 bills: 1

$5 bills: 0

$1 bills: 3

1 Answer

6 votes

Here is code in C.

#include <stdio.h>

//main function

int main(void)

{ //variable to store input amount

int amount;

printf("Enter a dollar amount:");

//reading the input amount

scanf("%d",&amount);

//calcutating and printing the $20 bills

printf("\\$20 bills:%d",amount/20);

//update the amount After reducing the $20 bills

amount=amount%20;

//calcutating and printing the $10 bills

printf("\\$10 bills:%d",amount/10);

//update the amount After reducing the $10 bills

amount=amount%10;

//calcutating and printing the $5 bills

printf("\\$5 bills:%d",amount/5);

//update the amount After reducing the $5 bills

amount=amount%5;

//calcutating and printing the $1 bills

printf("\\$1 bills:%d",amount/1);

return 0;

}

Step-by-step explanation:

According to the code, first it will ask user to give input amount.Then it will find the total bills for $20 and print that number, then it update the amount value after reducing them from the amount.Then it will calculate total bills for $10 and print that number then it updates the amount after reducing them from amount.Similarly it will calculate for $5 bills and $1 bills and print their values.

Output:

Enter a dollar amount:93

bills of $20 :4

bills of $10 :1

bills of $5 :0

bills of $1 :3

User Tgrez
by
5.2k points