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

Pseudocodes

The document contains 5 questions asking to write pseudo code for various algorithms. These include a basic calculator, finding the largest of 3 numbers, calculating bonuses based on years of service, checking if a number contains zero, and unit conversion.

Uploaded by

Hamza Mukhtar
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)
10 views2 pages

Pseudocodes

The document contains 5 questions asking to write pseudo code for various algorithms. These include a basic calculator, finding the largest of 3 numbers, calculating bonuses based on years of service, checking if a number contains zero, and unit conversion.

Uploaded by

Hamza Mukhtar
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

Q.1 Write a pseudo code of a calculator. Ask user about operation and both operands.

Output
the answer. For your pseudo code, you will use both of the selection statements.

INPUT X
INPUT Y
INPUT Operator

CASE Operator OF
“+”: PRINT X + Y
“-”: PRINT X – Y
“*”: PRINT X * Y
“/”: IF Y <> 0
THEN PRINT X / Y
ELSE PRINT “Cannot divide by zero”
ENDIF
OTHERWISE PRINT “Not a valid operator”
ENDCASE

Q.2 Write an algorithm using pseudo code to find the largest number between three numbers.

INPUT X
INPUT Y
INPUT Z

IF X > Y AND X > Z


THEN PRINT “X is the largest”
ENDIF

IF Y > Z AND Y > X


THEN PRINT “Y is the largest”
ENDIF

IF Z > Y AND Z > X


THEN PRINT “Z is the largest”
ENDIF

Q.3 Write an algorithm using pseudo code. A company decided to give bonus of 15% to
employee if his/her year of service is more than 10 years. Ask user for their salary and year of
service and print the net bonus amount.

INPUT Salary
INPUT Year

IF Year > 10
THEN PRINT 15 * Salary / 100
ELSE PRINT “Not qualified for a bonus”
ENDIF

Q.4 Write a pseudo code. Ask user to enter any positive integer from 1 to 50. Output either the
integer contains any zero in it or not.

PRINT “Please input a positive integer between 1 and 50”


INPUT X

IF X < 1 OR X > 50
THEN PRINT “Number out of range”
ELSE IF X % 10 == 0
THEN PRINT “It contains a zero”
ELSE PRINT “It does not contain a zero”
ENDIF
ENDIF

Q.5 Write a pseudo code. Ask the user about units. For Kilogram press 1, for Kilometre press 2,
for Kilobyte press 3, and for mile press 4. You have to convert Kilogram into grams, Kilometres
into meters, Kilobytes into bytes, and miles into both, kilometres and meters. Use both selection
statements for this pseudo code.

INPUT X
PRINT “ For Kilogram press 1, for Kilometre press 2, for Kilobyte press 3, and for mile press 4”
INPUT Conversion

IF X < 0 THEN
PRINT “The number you entered is invalid”
ELSE CASE Conversion OF
“1”: PRINT “Grams:” + X * 1000
“2”: PRINT “Meters:” + X * 1000
“3”: PRINT “Bytes:” + X * 1024
“4”: PRINT “Kilometers:” + X * 1.6
PRINT “Meters:” + X * 1.6 * 1000
OTHERWISE PRINT “The unit you provided is invalid”

ENDCASE
ENDIF

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy