1. Write a program to check if the following condition satisfies for a user inpu
ID: 3862285 • Letter: 1
Question
1.
Write a program to check if the following condition satisfies for a user input
number:
ABC = A! + B! + C!
Example: 145 = 1! + 4! + 5! = 1+24+120 = 145
(5
points)
2.
Suppose we can buy a chocolate bar from the vending machine for
$1 each
.
Inside every chocolate bar
,
there
is a coupon. We can redeem
7 coupons
for one
chocolate bar from the machine. We would like to know how many choc
olate
bars can be eaten, including those redeemed via coupon, if we have
n
dollars.
For example, if we have 20 dollars then we can initially buy 20 chocolate bars.
This gives us 20 coupons. We can redeem 14 coupons for 2 additional chocolate
bars. Thes
e two additional chocolate bars have 2 more coupons, so we now have
a total of 8 coupons when added to the six leftover from the original purchase.
This gives us enough to redeem for one final chocolate bar. As a result we now
have 23 chocolate bars and
2 leftover coupons.
Write a program that inputs the
number of dollars and outputs how many chocolate bars you can collect after
spending all your money and redeeming as many coupons as possible. Also
output the number of leftover coupons. The easiest
way to solve this problem is
to use a loop.
(10
points)
3.
A credit card company currently has three member levels, Platinum, Gold, and
Silver. Each credit card has a different interest rate:
•
Platinum member: 1% per month
•
Gold member: 2% per month
•
Silver member:
3% per month
If Platinum or Gold level customers make a late payment, then their interest rate for
the month doubles. For example, if a Platinum member is late, then his interest rate
increases from 1% to 2% for the month.
If a Silver level customer is
late on a payment, their interest rate does not increase.
Instead, they are assessed a flat $20 penalty for being late.
For this assignment, you will write a program that calculates the minimum payment,
which is 2% of the principle plus any interest and f
ees. You will also need to
calculate the percentage of the payment that goes to the principle. This is given by
Explanation / Answer
Answer 1:
#include<stdio.h>
int main()
{
int no, or, sum = 0;
//Accept a number
printf(" Enter a number: ");
scanf("%d",&no);
//Creates a duplicate copy of the number
or = no;
//Loops till number is not equal to zero
while(no != 0)
{
//Calculates the factorial of the digit of the number and add it with sum
sum += factorial(no % 10);
no /= 10;
}//End of while
//If original number is equal to sum
if(or == sum)
printf(" Satisfies for a user input number");
else
printf(" Not satisfies for a user input number");
}//End of main
//Returns the factorial of given digit of a number
int factorial(int no)
{
int x, f = 1;
//Loops from 1 to the number
for(x = 1; x <= no; x++)
//Multiply number with x value and stores it in f again
f *= x;
//Returns the factorial
return f;
}//End of function
Output 1:
Enter a number: 145
Satisfies for a user input number
Output 2:
Enter a number: 25
Not satisfies for a user input number
Answer 2:
#include<stdio.h>
int main()
{
//Variable declaration and initialization
int dollar, rem, cho = 0, cou = 0, quo;
//Accepts initial amount you have
printf(" Enter Number of Dollars you have: ");
scanf("%d", &dollar);
//Assigns dollars to number of chocolates initially
cho = dollar;
//Assigns coupons to number of chocolates initially
cou = dollar;
//Loops till coupons less than 7
do
{
//Finds the quotient
quo = cou / 7;
//Finds the remainder
rem = cou % 7;
//Adds quotient with chocolate and stores it in chocolate
cho += quo;
//Multiply quotient to 7 and subtract it from coupons and store it in the coupon
cou -= (quo * 7);
//Add the coupons value with the quotient and store it in the coupon
cou += quo;
}while(!(cou <= 7));
//Displays the information
printf(" Number of chocolate bars = %d", cho);
printf(" Left over coupons = %d", rem);
}//End of function
Output 1:
Enter Number of Dollars you have: 20
Number of chocolate bars = 23
Left over coupons = 1
Output 2:
Enter Number of Dollars you have: 25
Number of chocolate bars = 28
Left over coupons = 4
Answer 3:
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.