if… else if programs
1. A salesman gets commission on the following basis
Sales amt commission rate
500-20000 5%
20001 – 50000 10%
50001 -80000 15%
Accept sales as input. Calculate commission amount ,display
commission amount and commission rate .
2. The standard form of quadratic equation is given by ax 2+bx+c=0
where
d= b2-4ac is known as discriminant. The value of the discriminant
determines the nature of the roots of the equation.
Value Nature
If d>0 roots are real and unequal
d=0 roots are real and equal
d<0 roots are imaginary
Write a program to determine the nature of the roots of quadratic
equation by taking a, b, c inputs from the user.
3. Write a program to input name of the customer and no. of litres of
water used for their household usage. Calculate the bill amount by
using following table.
No. of litres Cost per litre(cpl)
Upto 20000 0.10 paise
20001 – 50000 0.12 paise
50001 – 100000 0.14 paise
>100000 0.15 paise
Bill amount = no. of litres * cpl
4. In an examination, the grades are awarded to the students in ‘Science’
according to the average marks obtained in the examination.
Marks Grades
80% and above Distinction
60% or more but less than 80% First Class
45% or more but less than 60% Second class
40% or more but less than 45% Pass
Less than 40% Promotion not granted
Write a program to input Student name, marks in Physics, Chemistry and
Biology. Calculate the average marks. Display the student name , average
marks and the grade obtained.
5. Write a program to input number from the user and check whether the
number entered is a single digit, two digits or a three digits number
and perform the following tasks.
i) If it is a single digit number then display its square.
ii) If it is a two digit number then display its square root.
iii) If it is a three digit number then display its cube root.
iv) Otherwise display the message “The number entered is more
than three digits”.
6. WAP to input a movie name, rating from 0 to 5 . Display movie name,
rating and result by using the following table.
Rating Result
0 – 1.0 Flop
1.1 – 2.5 Average
2.6 – 3.0 Watchable
3.1 – 4.0 Super hit
4.1 – 4.5 Super duper hit
4.6 – 5.0 blockbuster
7. Write a program to compute the amount that a customer pay for the
taxi that he/she hires based on the following conditions.
Kms travelled amount per km
First 10 kms 25
Next 40 kms 22
Next 50 kms 19
Above 100 kms 15
Input the customer name, cab number and the number of kms
travelled by him/her.
8. Electricity board charges the bill depending on the number of units
consumed(per month) as per the given tariff.
Units consumed charges
First 100 units Rs. 40paise per unit
Next 200 units Rs 60 paise per unit
Above 300 units Rs 1.00 paise/unit
WAP to input name of the customer, consumer number , month and
units consumed. Meter rent is also charged from each customer
which is Rs. 250.
Calculate and display the electricity bill with all the details.
9. Electronics world has announced an off-season discount on purchase of
certain item as per the given tariff.
Amount discount on AC
Upto Rs. 20,000 3%
Rs. 20,001 – Rs. 40,000 7%
Rs. 40,001 – Rs. 60,000 10%
More than 60,000 15.5%
Write a program to input the amount of purchase. However the
customer has to pay 12.5% as sales tax on the price after the
discount. Compute and print the net amount to be paid by the
customer along with the name.
Net amount = amount of purchase – discount
10. WAP to input radius(r) and any one of the choice 1,2,3 or 4.
Choice area
ch==1 circle( πr2)
ch==2 sphere (4 πr2)
ch==3 hemisphere (3πr2)
ch==4 semi-circle (πr2/2)
11. Computer salesman gets commission on the following basis
Sales amt commission rate
0-20000 3%
20001 – 50000 12%
50001 and more 20%
Accept sales as input. Calculate commission amount and display
commission amount and commission rate .
12. WAP to input name of an employee and monthly
salary .Display he/she designation by using the following table.
Salary designation
Upto 10,000 worker
10001 – 30000 supervisor
30001 - 50000 Asst. manager
50001- 75000 Manager
Above 75000 CEO
13. A cloth showroom has announced festival discounts and the gifts
based on the purchase of items i.e. total cost, discount and gift is given
below.
Total cost Discount Gift
Upto 2000 2% Wallet
2001 – 10,000 5% Hand bag
10,001- 20,000 10% Wrist watch
Above 20,000 12% Wall clock
Write a program to accept a customer name, contact number, total cost
and find the discount and print the customer name, total cost, contact
number, discount along with a gift.
14. Kumar Electronics has announced the following seasonal discounts
on purchase of certain items.
Purchase amount Discount on laptop Discount on desktop PC
Upto 25000 0.0% 5.0%
25,001 – 50,000 5.0% 7.5%
50,001 – 1,00,000 7.5% 10.0%
More than 1,00,000 10.0% 15.0%
WAP to inpout name, amount of purchse and tyoe of purchase (‘L’
for laptop and ‘D’ for desktop ) by a customer. Compute and print
the net amount to be paid by a customer along with his name.
(net amount = amount of purchase – discount)
15. WAP to enter three sides of a triangle and check whether the
triangle is possible or not. If possible , then display whether it is an
Equilateral, an Isosceles or a scalene triangle, otherwise display the
message ‘Triangle is not possible’.
16. In an examination , the grades are awarded to the students in
‘Science’ according to the average marks obtained in the examinatio
Marks Grades
80% and above Distinction
60% or more but less than 80% First division
45% or more but less than 60% Second division
40% or more but less than 45% Pass
less than 40% Promotion not granted
WAP to input name and marks in Physics, Chemistry and Biology.
Calculate the average marks. Display the name, average marks and the
grade obtained.
17. WAP to enter three sides of a triangle and check whether the
triangle is possible or not. If possible , then display whether it is an
Equilateral, an Isosceles or a scalene triangle, otherwise display the
message ‘Triangle is not possible’.
18. In an examination , the grades are awarded to the students in
‘Science’ according to the average marks obtained in the examination
Marks Grades
80% and above Distinction
60% or more but less than 80% First division
45% or more but less than 60% Second division
40% or more but less than 45% Pass
less than 40% Promotion not granted
WAP to input name and marks in Physics, Chemistry and Biology.
Calculate the average marks. Display the name, average marks and the
grade obtained.
Switch case programs
19. Write a program to display the menu as given below:
Menu – Area of
1. Rectangle
2. Square
3. Circle
4. Triangle
5. Exit
Enter your choice
Perform the operation based on user’s choice and display the result.
[ area of Rectangle = l x b , Square = s2, Circle = Pir2 (pi=3.14),
Triangle =½ x b x h]
20. Using switch case statement, Write a program to calculate the
volume of different solids by using the given formulae. (Use Math.PI for
pi)
1- cuboid volume= l b h
2- cylinder volume= pi r2 h
3- cone volume = 1 pi r2h
3
4 – sphere volume = 4 pi r 2
3