0% found this document useful (0 votes)
7 views4 pages

Programs Frank Chapter 2

The document provides a series of programming exercises focused on conditional and iterative constructs in programming. It includes tasks such as calculating age for voting eligibility, computing discounts on purchases, determining commissions for salesmen, and calculating various bills and wages. Additionally, it covers mathematical problems involving prime numbers, factorials, and series calculations.

Uploaded by

aishikasaha.kat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views4 pages

Programs Frank Chapter 2

The document provides a series of programming exercises focused on conditional and iterative constructs in programming. It includes tasks such as calculating age for voting eligibility, computing discounts on purchases, determining commissions for salesmen, and calculating various bills and wages. Additionally, it covers mathematical problems involving prime numbers, factorials, and series calculations.

Uploaded by

aishikasaha.kat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Frank Chapter 2 Solution

Recap of Programming using Conditional and Iterative Constructs


1. Write a program to input age, If age is 18 or above, print “You can vote!” If age is less than 18,
calculate after how many years the person will be allowed to vote and display “You can vote after
_______ years”.
Solution:

2. Write a program to calculate the final bill of a customer in a store. The discount structure is as
follows:

Purchase in Discount
Rupees
<=1000 Nil
1001 to <=5000 5%
>5000 10%
Print the total purchase, amount of discount and final bill.

3. Write a program to calculate and print commission of a salesman according to the following criteria:

Sales in Commission
Rupees
0-1000 0%
1001-3000 5%
3001-5000 10%
>5000 15%
In addition, if the total commission paid to the salesman exceeds Rupees 1000, he is paid an
additional bonus of 200.
Input the sales, calculate and print the commission, sales and total commission with bonus.
4. Write a program to calculate the telephone bill of a customer. The billing method is as follows:
a. First 100 minutes at 1.00/call
b. Next 100 minutes at 1.50/call
c. Excess minutes at 2.50/call

5. A worker is paid at the hourly rate (R) for the first 40 hours of work in a week. Thereafter, he is paid
at 1.25 times the hourly rate (R) for the next 16 hours and at 1.5 times the hourly rate (R) for further
hours of work in the week. Taking the number of hours (H) and the rate/hour (R) as inputs, write a
program to calculate weekly wage (W). Print the weekly wage for the employee.

6. Design a class named ‘Investment’, to calculate the amount collected by an investor for different
interest rates based on the formula A=P(1+R/`00)N where A = amount due, P=amount invested, R =
rate of interest and N=number of years.
The bank offers the following rates:

N R%
1 year 8
2 years 8.5
3 years 9

7. The months of the year are related to seasons as follows:

Month Season
2,3,4,5 Summer
6,7,8,9 Monsoon
10,11,12,1 Winter

Write a program that accepts a number for the month and gives the output for the appropriate
season for that month.

8. Write a menu-driven program to find the area of an equilateral triangle, a right-angled triangle, a
scalene triangle respectively.
Hint: Area of an equilateral triangle = √
3 a2
4
bh
Area of a right-angled triangle =
2
a+b+ c
Area of a scalene triangle = √ s ( s−a )( s−b ) ( s−c ) where s =
2

9. Write a program using switch/case to find the volume of a cube, a sphere and a cuboid. For an
incorrect choice, an appropriate message should be displayed.
Hint: Volume of a cube = s×s×s
4
Volume of a sphere = × π ×r ×r × r
3
Volume of a cuboid = l ×b × h

10. Allow a user to enter a number.


a. Check whether the number is divisible by 2 and by 7.
b. Check whether the number is divisible by 2 but not by 4.
c. Check whether the number is divisible by 3 and not by 5.
Output the appropriate message.
Solution:

11. Accept three consecutive numbers, a, b, c and check whether they are Pythagorean Triplets or not.
Pythagorean triplets are a2+b2=c2
12. A store sells several items and a discount is given according to the number of items bought.
Quantity Discount
bought
<15 5% of gross
>=15 to <25 10% of gross
>=25 to <40 15% of gross
>=40 20% of gross
Write a program to do the following:
Input : Item number, Quantity bought and Rate
Calculate : Gross amount = Quantity bought * Rate
Output : Net payable = Gross amount – Discount
Item number, Gross amount, Discount, Net payable

13. Input two numbers. Find the greater of the two numbers and then swap the numbers. Do not use a
third variable for swapping.
14. Using the ternary operator, write a program to input a number and check whether the given number
is odd or even.
15. Writer a program to input three integers. Using ternary operator, print the largest of the three
numbers.

16. Write a program to print all prime numbers from 100 to 500.

17. Write a program to print all perfect squares from 1 to 100.


Solution:

18. Write a program to print the total of all three-digit numbers.

19. Write a program to print the factorials of numbers from 1 to 10.

20. Write a program to accept a number and check whether it is a special number. A special number is
one where the sum of the factorial of the digits is equal to the number input, for example, 145 is a
special number as 5! + 4! +1! = 145
Program Based On Series:
21. S=1+1+2+1+2+3+….n terms

22. S=1!+2!+3!+….n! terms


Solution:

x x x x
23. S= + + + … terms
2! 3! 4! n!

24. S=1 11 111….n terms


25. S=1 12 123 1234…..n terms
26. S=1,4,9,16,25….n terms

27. S=(1×2)+(2×3)+….(19×20)

28. S=1+(1×2)+2+(1×2×3)+3+….9+(1×2×3×…..10)
1 1 1 1
29. s= + + + +… n terms
2 4 8 16
1 1 1 1
30. s= − + − + … n terms
2 3 4 5

You might also like