C Programming: Program for making change

/* Header Files */
#include <stdio.h>
#define QUARTER 25;
#define DIME 10;
#define NICKEL 5;

/* Main Function */
int main()
{
/* Variable Declaration */
int amount;
int myquarters;
int mydimes;
int mynickles;
int pennies;

/*Input*/
printf("Enter amount of change: ");
scanf("%d",&amount);

/*Quarters*/
myquarters = amount / QUARTER;
amount = amount % QUARTER;

/*Dimes*/
mydimes = amount / DIME;
amount = amount % DIME;

/*Nickles*/
mynickles = amount / NICKEL;

/*Pennies*/
pennies = amount % NICKEL;

/*Output*/
printf("%d quarters, %d dimes, %d nickels, %d pennies\n", myquarters, mydimes, mynickles, pennies);
printf("\n");

/* Main Function Return Statement */
return 0;
}

This example shows:

  • how to use the modulus operator

Leave a Reply

Your email address will not be published. Required fields are marked *