You are on page 1of 1

EXERCISE-1 : A small business wishes to use a computer program to calculate how to make up the

pay packets for its employees. The program should read the total amount to be paid, and print the
number of £20, £10 and £5 notes required, and the amount of £1, 50p, 20p, 10p, 5p, 2p and 1p coins
needed. It is union requirement that every pay pocket should contain at least 40p in coins, and at least
one £5 note. Subject to this restriction, the pay pocket should contain as few coins and notes as
possible. Note that £1=100p.

Write a program to provide the required information, and test it with a wide variety of cases, including
those with a total pay of £125.39 and £65.40.

EXERCISE 2 : Write a program that will determine how much income tax a person pays, given the
following basis for taxation :

Income Tax Rate


First 5000 USD 0%
Next 15000 USD 25 %
Everything over 20000 USD 32 %

EXERCISE 3 : Write a program that reads a pH value between 1.0 and 14.0 and prints a message
giving the colour of a certain chemical indicator for that pH value. The program should print an
intermediate colour (orange, green, purple, or pink) if the pH is in the critical range.
Colour pH range of Colour
Indicator in acid colour change in base
Methyl orange Red 3.1 – 4.4 Yellow
Bromthymol blue Yellow 6.0 – 7.6 Blue
Litmus Red 4.5 – 8.3 Blue
Phenolphthalein Colourless 8.3 – 10.0 Red

EXERCISE 4 : If the lengths of the sides of a triangle are a, b, and c, then the area of the triangle
can be computed from Heron's formula, which is
𝑎𝑟𝑒𝑎 = √𝑠 (𝑠 − 𝑎)(𝑠 − 𝑏)(𝑠 − 𝑐)

where s is one half the sum of the lengths of the sides of the triangle.

Write a program that asks for and reads the lengths of the three sides, then determines whether those
three sides can form a triangle. If they can, the program should display the area. If not, it should say
they do not form a triangle.

The sum of two sides must add up to be greater than the length of the remaining third side, i.e., a + b
> c ; b + c > a ; and a + c > b

EXERCISE 5 : Write a program that accepts a positive integer as its input and informs the user of all
the following:

a) whether the number is odd or even


b) whether it is divisible by seven
c) whether it is a perfect square (that is, its square root is a whole number).

EXERCISE 6 : Write a program checking if a given year is a leap year.

Information: All years which are perfectly divisible by 4 are leap years except for century years (years
ending with 00) which is a leap year only it is perfectly divisible by 400. For example, years like 2012,
2004, 1968 are leap years but 1971, 2006 are not leap years. Similarly, 1200, 1600, 2000, 2400 are
leap years but 1700, 1800, 1900 are not.

You might also like