[go: up one dir, main page]

0% found this document useful (0 votes)
6 views2 pages

03 Practice Repetition

The document outlines a programming practice assignment for CMP-140 Programming Fundamentals, focusing on problem-solving using pseudo code. It includes various tasks such as testing pseudo code for errors, calculating tax based on income, and finding the greatest common divisor. The exercises aim to enhance understanding of repetition structures and basic programming concepts.

Uploaded by

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

03 Practice Repetition

The document outlines a programming practice assignment for CMP-140 Programming Fundamentals, focusing on problem-solving using pseudo code. It includes various tasks such as testing pseudo code for errors, calculating tax based on income, and finding the greatest common divisor. The exercises aim to enhance understanding of repetition structures and basic programming concepts.

Uploaded by

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

CMP-140 Programming Fundamentals

BS SE/CS Fall 2018 Issue Date: 18-Feb-2019


Practice - 03

Objective:
• To get a grip on problem solving involving repetition structure and a couple of exercises to
practice dry run.

Devise Solution of the following problems using Pseudo Code

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.

1- Declare m, n, upperBound 9- maxFactor = 1


2- m = 24 10- Repeat Until (factor <= upperBound)
3- n = 30 10.1- If (m % factor == 0 AND n % factor == 0)
4- upperBound = n 10.1.1- maxFactor = factor
5- If ( m <= n ) 10.1.2- print maxFactor
5.1- upperBound = m 10.2- factor = factor + 1
6- Print upperBound
7- Declare factor, maxFactor
8- factor = 2

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.

PUCIT, University of the Punjab, Lahore, Pakistan. Page 1 of 2


© Fareed Ul Hassan Baig
CMP-140 Programming Fundamentals
BS SE/CS Fall 2018 Issue Date: 18-Feb-2019
Practice - 03

4. Input N numbers from user and find the largest value entered by user.

5. Input a number N and display all the positive divisors of N.

6. Calculate the factorial of a positive integer 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.

14. Calculate the Grade Point Average (GPA) for a semester.


GPA for a semester is calculated by:
a. Multiplying grade points with the credit hours in each course to obtain total grade points
b. Add up the total grade points to cumulative Grade Points and divide by the total number
of credit hours in order to calculate the GPA for a semester.
For Example:

Subject Marks Cr. Hrs. Grade Point


ITC 70 3 3
(3*3+3*4+4*3.7+1*2.6)/11=
PF 87 3 4
39.4/11 = 3.49 GPA
EMT 83 4 3.7
PF Lab 66 1 2.6
Ask the user about the number of subjects he studied in the semester and then ask for the
marks in these subjects and their credit hours in order to calculate GPA.

15. Write a program, which takes input of two integers. It then displays the greatest common
devisor of the two entered integers.

PUCIT, University of the Punjab, Lahore, Pakistan. Page 2 of 2


© Fareed Ul Hassan Baig

You might also like