03 Practice Repetition
03 Practice Repetition
Objective:
• To get a grip on problem solving involving repetition structure and a couple of exercises to
practice dry run.
1. Test/run the following pseudo code. If it contains any grammar/syntax error then mention that
error otherwise give output on screen and variable status in RAM. Assume that user input oa =
624
1- Declare oa, r, da, exp 7- exp = r
2- exp = 1 8- r = oa
3- Print “Enter number : ” 9- oa = exp
4- Input oa 10- Print “Number : ”, da
5- da = 0
6- Repeat until ( oa >= 1 )
6.1- r = oa % 10
6.2- oa = oa / 10
6.3- da = da + r * exp
6.4- exp = exp * 8
RAM
oa
r
da
exp
Console
2. What output does this program produce? Please pay attention to all of the print statements.
RAM
m
n
upperBound
factor
maxFactor
Console
3. Input ‘N’ numbers from user and sum up only those numbers, which are odd. Also display the
count of odd numbers entered.
4. Input N numbers from user and find the largest value entered by user.
7. The kingdom of ABRACADABRA, where the unit of currency is abra, has the following income tax
code:
First 5,000 abra: 0% tax
Next 10,000 abra: 10% tax
Next 20,000 abra: 15% tax
Abras after 35,000: 20% tax
For example, someone earning 38,000 abra would owe:
5,000 * 0.00 + 10,000 * 0.10 + 20,000 * 0.15 + 3,000 * 0.20 = 4600 abras
Write a pseudo code that ask user about his income and report the tax that he has to pay.
8. Input two numbers ‘a’ and ‘n’ from user. And calculate an.
9. Write a pseudo code to enter any number and calculate product of its digits.
10. Input a number and find whether the number is prime or not.
11. Assuming the ocean’s level is currently rising at about 1.5 millimeters per year; write a pseudo
code that displays a table showing the number of millimeters that the ocean will have risen each
year for the next 25 years.
12. Input a base-10 number and display its equivalent octal number.
13. The Last Stop Boutique is having a five-day sale. Each day, starting on Monday, the price will
drop 10% of the previous day’s price. For example, if the original price of a product is $20.00,
the sale price on Monday would be $18.00 (10% less than the original price). On Tuesday the
sale price would be $16.20 (10% less than Monday). On Wednesday the sale price would be
$14.58; on Thursday the sale price would be $13.12; and on Friday the sale price would be
$11.81. Develop a solution that will calculate the price of an item for each of the five days,
given the original price.
15. Write a program, which takes input of two integers. It then displays the greatest common
devisor of the two entered integers.