93.8k views
0 votes
A cashier distributes change using the maximum number of five dollar bills, followed by one dollar bills. For example, 19 yields 3 fives and 4 ones. Write a single statement that assigns the number of one dollar bills to variable numOnes, given amountToChange. Hint: Use the % operand.

Sample program:
#include
int main(void) {
int amountToChange = 0;
int numFives = 0;
int numOnes = 0;
amountToChange = 19;
numFives = amountToChange / 5;

printf("numFives: %d\\", numFives);
printf("numOnes: %d\\", numOnes);
return 0;

1 Answer

4 votes

Answer:

The correct program to this question as follows:

Program:

//header file

#include <stdio.h> //include header file for using basic function

int main() //defining main method

{

int amountToChange=19,numFives,numOnes; //defining variable

numFives = amountToChange/5; //holding Quotient

numOnes = amountToChange%5; //holding Remainder

printf("numFives: %d\\", numFives); //print value

printf("numOnes: %d\\", numOnes); //print value

return 0;

}

Output:

numFives: 3

numOnes: 4

Step-by-step explanation:

In the above program first, a header file is included then the main method is declared inside the main method three integer variable is defined that are "amountToChange, numFives, and numOnes", in which amountToChange variable a value that is "19" is assigned.

  • Then we use the numFives and the numOnes variable that is used to calculate the number of 5 and 1 , that is available in the amountToChange variable.
  • To check this condition we use (/ and %) operators the / operator is used to hold Quotient value and the % is used to hold Remainder values and after calculation prints its value.

User Shishy
by
3.9k points