Question

C Programming Language Problem Title: Discount Jojo is browsing the internet while suddenly he sees an...

C Programming Language

Problem Title: Discount

Jojo is browsing the internet while suddenly he sees an ad about the new cafe. The promotion is if the price of an item is N dollars, then you can buy the second item for half the price, the third item for a quarter of the original price, and so on, but if it becomes less than M dollars, then you have to pay M dollars. He wonders how much he has to pay if he buys K item

Format Input

The first line will contain an integer T, the number of test cases. Each test case will have 3 integers N, M, and K, each denoting the original price, the minimum price, and the amount Jojo is going to buy.

Format Output

For each test case, print “Case #X: “ (X starts with 1), then followed by the price Jojo has to pay rounded to 3
decimal digits.
.

Constraints

• 1 ≤ T ≤ 10
• 1 ≤ M ≤ N ≤ 1000000000
• 1 ≤ K ≤ 1000000000

Sample Input & Output (standard input & output)

3

10 5 3

Case #1: 20.000

100 5 3

Case #2: 175.000

100 100 4

Case #3: 400.000

Explanation

In the first case, the original price is 10 dollars, the price for the second item is 5 dollars, the price for the third item is 5 dollars too because 2.5 is less than 5. In the third case, all item won’t be lower than the original price.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Discount problem CODE(in C):

#include <stdio.h>

int main(void) {

int T;

long long M,N,K; //declaring our variables

double price; //Declaring a price variable

scanf("%d", &T); //Promting the user to enter the number of test cases (T)

for(int i=1; i <= T; i++){

price = 0;

scanf("%lld %lld %lld", &N, &M, &K); //Prompting the user to input the values

double A = N; //Taking a duplicate of the original price as double variable

while (K > 0){

if (A < M){ //If the price is less than M

price = price + M; //Incrementing price with M dollars

K = K - 1;

continue;

}

price = price + A; //else incrementing price with A

A = A/2; //Updating A (i.e., Making the original price half for every iteration)

K = K - 1 ;

// printf("%f %f\n",sum,A);

}

printf("Case #%d: %.3f\n",i,price);//Printing on the output screen

}

return 0;

}



CODE IMPLEMENTATION:

TESTING OUR CODE (OUTPUT 1):

TESTING OUR CODE(OUTPUT 2):

NOTE:

# We must declare N,M,K as long long integers because, the given constraints for those variables are very large.

# Any questions or clarifications regarding this question can be asked in the comments section.

Add a comment
Know the answer?
Add Answer to:
C Programming Language Problem Title: Discount Jojo is browsing the internet while suddenly he sees an...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write in C language . Thank you Count Sheep Jojo is having problem to sleep at...

    Write in C language . Thank you Count Sheep Jojo is having problem to sleep at night. He can't fall asleep and it makes him feel tired every day. Having this problem, Jojo told his friend Bibi, and Bibi advised him to do sheep counting while he tries to sleep. Jojo decided to try using this trick for N nights, to test its effectiveness. Jojo realized that he would fall asleep if he imagined a total of 10 white sheep....

  • C language Thank you Jojo is going to a restaurant. There are N foods listed in...

    C language Thank you Jojo is going to a restaurant. There are N foods listed in the menu, and the items are sorted increasingly based on its price. Now Jojo is wondering how many foods are there with price P. As the number of food in the menu can be a lot, Jojo will need your help to answer his questions. Jojo knows you can count really fast, so he will give you M questions. Format Input Input begins with...

  • C Programming Language The code below matches the sample input/output but is marked wrong. Are there...

    C Programming Language The code below matches the sample input/output but is marked wrong. Are there other ways to do this problem? The focus is on recursion and functions. #include<stdio.h> int joCheck(unsigned long long int number) { if(number % 7 == 0 || number % 8 == 0) { return 1; } else return 0; } int main() { int cases = 0; scanf("%d", &cases); for(int i = 1; i<=cases; i++) { unsigned long long int number; scanf("%d", &number); if(joCheck(number)...

  • write in C language Decoration Lights Jojo is currently working in an office as a security....

    write in C language Decoration Lights Jojo is currently working in an office as a security. Every night, after everyone returned home, he needs to make sure all decoration lights in the office is turned off. The decoration lights are unique: each of them has a timer that will switch the light on or off every two seconds. The lights are also arranged so well that each two neighboring lights will have different state (on/off). As long as the timer...

  • C Programming Language Problem Title: Komodo National Park Do You know that Komodo National Park, located...

    C Programming Language Problem Title: Komodo National Park Do You know that Komodo National Park, located in Nusa Tenggara Timur (NTT), is a World Heritage Site by UNESCO, the specialized agency under United Nations (UN). One day, Lili and Bibi were on vacation on one of the islands in the Komodo National Park area and they just realized that they were living alone on that island because the cot- tage owner was completing his unfinished business on the main island....

  • C Programming Language Problem Title : Climbing Stairs Bibi climbs stairs of a multi-leveled building. Every...

    C Programming Language Problem Title : Climbing Stairs Bibi climbs stairs of a multi-leveled building. Every time Bibi climbs a set of stairs, she counts the steps starting from 1 to the number of steps in that particular set of stairs while climbing the stairs. For example if she climbs two set of stairs, the first containing 5 steps and the second containing 3 steps, she will say 1, 2, 3, 4, 5, 1, 2, 3 and the total number...

  • Write in C language CEO's Problem Every CEO has their own unique problem, they say. The...

    Write in C language CEO's Problem Every CEO has their own unique problem, they say. The same goes to Jajo. Determining the fate of his newbom company is super tough. Every year, las board committee present him with S denoting the number of customers that use his company's services out of total M customers already in the market. And every year, C number of new customers will enter the market, and all of them will use his company's services Other...

  • C PROGRAMMING LANGUAGE Door of the Ancient Pandy is at the last stage of "Door of...

    C PROGRAMMING LANGUAGE Door of the Ancient Pandy is at the last stage of "Door of the Ancients", his favorite video game. His objective is to pass through a sacred door. There are two ways to do this: By defeating a mighty guardian and snatch the key to the sacred door, or by destroying the sacred door (with brute force) directly. Pandy has no confidence in fighting the mighty guardian, thus Pandy opts to use the second method. Pandy has...

  • *Notes : Code With C++ Programming Language Once upon a time there was a student who...

    *Notes : Code With C++ Programming Language Once upon a time there was a student who was quite smart on a campus. When he entered the time to work on his thesis, he had a dilemma. He is surrounded with various positive and negative energy auras from the surrounding environment. Fortunately, this student was awarded a special ability, where he was able to convert negative energy into positive energy and then absorb it. To be able to convert negative energy...

  • Topic:Data structures and algorithms programming Compiler:C++ 11, flag: -static -std=c++0x Boring job One day, Rick got...

    Topic:Data structures and algorithms programming Compiler:C++ 11, flag: -static -std=c++0x Boring job One day, Rick got a sequence of N magic numbers. In order to find the latent code in the sequence, he decides to do the following operations with a magic parameter K: Step (1) Take out the first k numbers from current sequences into a temporary sequence ni namn, and pick the largest element Vmax out of these k numbers, then subtract 1 from the remaining K-1 elements....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT