PROGRAMMING WORKSHEET
SEQUENCE
1. Write a program to output the message “Hello User”.
2. Write a program to input a person’s birth year and calculate and output his
current age.
3. A user wants to calculate the volume of a cube. Write a program that will allow
him to enter the length of one side and calculate and output its volume.
4. Create a program to accept the dimensions of a cuboid and calculate and output
its volume.
5. Write a program to accept three numbers and calculate and output the average.
SELECTION
1. Write a program to input the age of a person. If the age is greater than 40, output
“old” otherwise output “young”.
2. Write a program to read the name of a month, if the month is September or
December print “Great time to be born”
3. Create a program to read two numbers into variables S and B. The program should
store the smaller in S and the larger in B, and then print S and B.
4. Write an algorithm to allow a user to enter three numbers and print the largest with a
message.
5. The price for admission into the north stand of a stadium is $50, for the south stand
the price is $30, for the east stand price is $20 and for the west stand the price is $10
Write a program to read the stand, the number of spectators in the stand and
calculate the income for the stand.
6. A garment store is giving 20% discount on sales that are $400 and more. Write a
program to request the cost of a item and print the amount the customer has to pay.
7. Write a program to print the grade of a student given his marks based on the
following key.
GRADE KEY:
A+ > 80% B- 45-49%
A 70-79% C+ 40-44%
A- 65-69% C 30-39%
B+ 60-64% U < 30%
B 50-59%
REPETITION
For Loop
1. Construct a for loop to print the numbers 1 to 10.
2. Construct a for loop to print the numbers 1 to 10 in descending order.
3. Construct a for loop to print the first 10 odd numbers.
4. Construct a for loop to the even numbers between 20 and 100 inclusive.
5. Construct a for loop to positive multiples of five < 100.
6. Write a program to print a table of squares from 1 to 10. Each line must consist of
the square of a number and the square of the number.
7. Write a program to request a value for ‘n’ and print a table of squares from 1 to n.
8. Write a program to request values for first and last and print a table of squares
from first to last.
9. Write a program to print a conversion table from km to metres. The table ranges
from 5 to 100 km.
10. Write a program to request a value for n; the user is asked to enter n numbers
one at a time. The program calculates and prints the sum of the numbers.
While Loop
1. Write a program to allow a user to enter a series of positive numbers and to
calculate and print the sum of the numbers and their average. The program is
terminated with 0.
2. Write a program to accept a series of numbers and find and display the largest
number.
3. Write a program to accept the weights of a number of persons and determine
and output heaviest.
4. A store has advertised a 15% sale on all items. Write a program that will accept
the name of the items a customer purchased, together with the original price. The
program should calculate the price of the item after the discount. It should also
output in one line the name of the item, the original price and the new price.
5. Write program that will accept a series of heights in metres and convert them to
centimetres before outputting them.
6. A user has a series of memory sizes in Kb. Write a program that will allow him to
read in the values and convert them to Mb and display the result.