Code For Alls..!

get the code!!

Sunday, 30 July 2017

Restaurant - Lucky Numbers Discount

Every day in a restaurant two numbers X and Y are considered lucky numbers.
If the bill amount B is divisible by X, then X% discount is offered.
If the bill amount B is divisible by Y, then Y% discount is offered.
If the bill amount B is divisible by both X and Y, then no amount is to be paid.
The program must accept X, Y and B and print the amount to be paid as the output (precision is up to 3 decimal places)
Input Format:
The first line contains B
The second line contains X
The third line contains Y
Output Format:
The first line contains the amount to be paid finally after discount.
Boundary Conditions:
1 <= X,Y <= 50
20 <= B <= 100000
Example Input/Output 1:
Input:
500
20
50
Output:
0.000
Example Input/Output 2:
Input:
100
9
10
Output:
90.000
C code:
#include<stdio.h>
#include <stdlib.h>
int main()
{
int n,x,y;
scanf("%d\n%d\n%d",&n,&x,&y);
if(n%x==0 && n%y==0)
printf("%.3f",0);
else if(n%x==0)
printf("%.3f",(n-((n*x)*.01)));
else if(n%y==0)
printf("%.3f",(n-((n*y)*.01)));
else
printf("%.3f",(float)n);
}

No comments:

Post a Comment