Final answer:
The C program prompts the user for an amount in cents, ensures it is within the 0-99 range, and prints the number of 50c, 20c, 10c, 5c, 2c, and 1c coins needed to make up that amount using if statements.
Step-by-step explanation:
To solve the problem of converting an integer amount of cents (0-99) into coins in C programming language, you can use the following approach:
#include
int main() {
int amount, remaining;
printf("Enter amount in cents (0-99): ");
scanf("%d", &amount);
if(amount < 0 || amount > 99) {
printf("Amount must be between 0 and 99.");
return 1;
}
printf("The coins required to make %d cents are:\\", amount);
if(amount >= 50) {
printf("50c coins: %d\\", amount / 50);
amount = amount % 50;
}
if(amount >= 20) {
printf("20c coins: %d\\", amount / 20);
amount = amount % 20;
}
if(amount >= 10) {
printf("10c coins: %d\\", amount / 10);
amount = amount % 10;
}
if(amount >= 5) {
printf("5c coins: %d\\", amount / 5);
amount = amount % 5;
}
if(amount >= 2) {
printf("2c coins: %d\\", amount / 2);
amount = amount % 2;
}
if(amount >= 1) {
printf("1c coins: %d\\", amount);
}
return 0;
}
This program starts by prompting the user to input an amount in cents. It checks if the amount is within the specified range and then calculates the number of each type of coin needed to make up the total amount, starting with the largest denomination and working down. It then prints out the number of each denomination needed.