P027.c ​
Metadata ​
- Author — Amit Dutta
- Last updated — 12 Dec 2025
- License — MIT License (See the LICENSE file for details)
Problem Statement ​
Problem Statement
Purchase Discount on Discount on Amount Laptop Desktop -------- ----------- ----------- Upto 20k 3.0% 5.0% 20001 - 50k 5.0% 7.5% 50001 - 75k 7.5% 10.5% more than 75k 10.0% 15.0% WAP to input amount of purchase and type of purchase ('L' : laptop, 'D' : desktop) and display the discount amount and the discounted price (Net Amount).
Source Code ​
Printing the code
To print this file, open it on GitHub and click Raw before printing, or use the Download Raw button above and print directly from that page.
c
#include <stdio.h>
#include <ctype.h>
int main()
{
double principal_amount, desktop_discount, laptop_discount, discount_amount, discounted_price;
char choice;
printf("Enter the purchase amount : ");
scanf("%lf", &principal_amount);
printf("Type of purchase ('L' : Laptop, 'D' : Desktop) : ");
scanf(" %c", &choice);
choice = toupper(choice);
if (principal_amount <= 20000)
{
laptop_discount = 0.03;
desktop_discount = 0.05;
}
else if (principal_amount > 20000 && principal_amount <= 50000)
{
laptop_discount = 0.05;
desktop_discount = 0.075;
}
else if (principal_amount > 50000 && principal_amount <= 75000)
{
laptop_discount = 0.075;
desktop_discount = 0.105;
}
else if (principal_amount > 75000)
{
laptop_discount = 0.1;
desktop_discount = 0.15;
}
switch (choice)
{
case 'L':
discount_amount = principal_amount * laptop_discount;
discounted_price = principal_amount - discount_amount;
printf("\nDiscount Amount : %g"
"\nDiscounted Price : %g",
discount_amount, discounted_price);
break;
case 'D':
discount_amount = principal_amount * desktop_discount;
discounted_price = principal_amount - discount_amount;
printf("\nDiscount Amount : %g"
"\nDiscounted Price : %g",
discount_amount, discounted_price);
break;
default:
printf("\nInvalid Input.");
return 1;
}
return 0;
}1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53