/* * Program to make change: * * Input: Non-negative integer N, number of pennies. * * Output: Numbers of dollars, quarters, dimes, nickels, pennies to * add up to N. The idea is to use the minimum number of smaller * coins (e.g., one dollar rather than four quarters). * * (Version using expressions in printf. Also uses #define to define * constants to maybe improve readability.) */ #include #define CENTS_PER_DOLLAR 100 #define CENTS_PER_QUARTER 25 #define CENTS_PER_DIME 10 #define CENTS_PER_NICKEL 5 int main(void) { int N; printf("enter number of pennies\n"); scanf("%d", &N); printf("You entered %d\n", N); printf("%d dollars\n", N / CENTS_PER_DOLLAR); N = N % CENTS_PER_DOLLAR; printf("%d quarters\n", N / CENTS_PER_QUARTER); N = N % CENTS_PER_QUARTER; printf("%d dimes\n", N / CENTS_PER_DIME); N = N % CENTS_PER_DIME; printf("%d nickels\n", N / CENTS_PER_NICKEL); N = N % CENTS_PER_NICKEL; printf("%d pennies\n", N); return 0; }