Write a C program that prints 1 if there is an exact change using nickels (5 cents), dimes (10 cents), quarters (25 cents), loonies ($1), toonies ($2) and bills and 0 if there is none. For example, if the change is $7.25 it prints 1 because, the change would be 7 loonies($1), two dimes and a nickel.
C code:
#include <stdio.h>
int main()
{
//initializing amount
float amt;
//accepting it
scanf("%f",&amt);
//checking if an exact change is possible
if((int)(amt*100)%200%100%25%10%5==0)
//printing 1
printf("%d",1);
else
//printing 0
printf("%d",0);
return 0;
}
Screenshot:
Input and Output:
Get Answers For Free
Most questions answered within 1 hours.