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
  • C Programming Language Problem Title: Jojo’s Hardest Problem (?) Jojo is enjoying his vacation with his...

    C Programming Language Problem Title: Jojo’s Hardest Problem (?) Jojo is enjoying his vacation with his family. Suddenly an instant message came in. Apparently there is a message from Lili : ”Jojo, don’t forget to check the forum. Who knows if there is an assignment before the exam” Jojo finally took the time to check the discussion forum and sure enough, there were some assignments given to his class. He immediately told his classmates. Jojo finds out one difficult problem...

  • 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 Programming Language Problem Title: Introduction to Computer Vision Jojo is an outstanding student who is...

    C Programming Language Problem Title: Introduction to Computer Vision Jojo is an outstanding student who is currently pursuing his Computer Science degree. In one of his Computer Vision lectures, his lecturer tackled a topic about binary thresholding. For simplicity, binary thresholding is an image filtering method used to separate low val- ued pixels (dark) from high valued pixels (bright). Each pixels in an image is classified as low or high based on a certain threshold K. If a pixel Pij...

  • 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: Introduction to Database Database is a structurized method for data storage...

    C Programming Language Problem Title: Introduction to Database Database is a structurized method for data storage and perform operations related to the data. There are Some simple operations that can be done by a database are Insert, Alter, Delete, and Query. There are N different integers stored. You are asked to create a database where you can carry out the following 4 operations : 1. I X - this operation is insert operation, inserting X to the database. 2. A...

  • 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...

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