Prog Sequence A PDF

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

Mr.

Mahmoud Moussa IGCSE CS 0984

Sequence Problems
Problem 01

Write an algorithm using pseudocode that Output the message:


Welcome to IGCSE CS 0984.
Solution
OUTPUT ("Welcome to IGCSE CS 0984.")

Problem 02

Write an algorithm using pseudocode that prompts the user for his/her last name and first name
separately and then prints a greeting like this:
Enter your last name: O'Connor
Enter your first name: Sandra
Hello, Sandra O'Connor

Solution
OUTPUT ("Enter your last name: ")
INPUT LastName
OUTPUT ("Enter your first name: ")
INPUT FirstName
OUTPUT ("Hello, "FirstName," ", LastName)

Problem 03

Write an algorithm, using pseudocode that calculate and display the sum of two integers
Solution
OUTPUT ("Enter first integer: ")
INPUT Number1
OUTPUT ("Enter second integer: ")
INPUT Number2
Sum ← Number1 + Number2
OUTPUT("Sum is ", Sum)

Problem 04

Write an algorithm, using pseudocode that calculate and display the product of three integers.
Solution
OUTPUT ("Enter first integer: ")
INPUT Number1
OUTPUT ("Enter second integer: ")
INPUT Number2
OUTPUT ("Enter third integer: ")
INPUT Number3
Product ← Number1 * Number2 * Number3
OUTPUT("The product is ", Product)

www.mahmoudmoussa.net 1
Mr. Mahmoud Moussa IGCSE CS 0984

Problem 05

Write an algorithm, using pseudocode that calculate and display the sum, product, difference and
quotient of two numbers
Solution
PRINT("Enter first integer: ")
INPUT Num1
PRINT("Enter second integer: ")
INPUT Num2
Sum ← Num1 + Num2
Product ← Num1 * Num2
Difference ← Num1 - Num2
Quotient ← Num1 / Num2
PRINT ("The sum is ", Sum)
PRINT ("The product is ", Product)
PRINT ("The difference is ", Difference)
PRINT ("The quotient is ",Quotient)

Problem 06

Write an algorithm, using pseudocode to convert a distance in miles and output the equivalent
distance in km (Km= Miles* 1.61)
Solution
OUTPUT ("Enter Miles: ")
INPUT Miles
KM ← Miles * 1.61
OUTPUT ("KM: ", KM)

Problem 07

Write an algorithm, using pseudocode to


 Input a length in inches.
 Calculate the equivalent in centimetres.
 Output the result.
Solution
INPUT "Enter inches: " Inches
Cm ← Inches * 2.54
OUTPUT Cm, " cm"

Problem 08

Write an algorithm, using pseudocode that reads in the radius of a circle, calculates its area and then
writes the calculated result.
Solution
CONSTANT PI ← 3.14159
OUTPUT("Radius = ? ")
INPUT Radius
Area ← PI * Radius * Radius
OUTPUT("Area = ", Area)

www.mahmoudmoussa.net 2
Mr. Mahmoud Moussa IGCSE CS 0984

Problem 09

Write an algorithm, using pseudocode that inputs from the user the radius of a circle as an integer
and prints the circle’s diameter, circumference and area. Use the value 3.14159 for π
Use the following formulas (r is the radius):
 diameter = 2r
 circumference = 2πr
 area = πr2
Solution
CONSTANT PI ← 3.14159
PRINT("Enter radius:")
INPUT Radius
PRINT("Diameter is " , ( 2 * Radius ))
PRINT("Area is " , (PI * Radius ^ 2 ))
PRINT("Circumference is " , (2 * PI * Radius ))

Problem 10

Write an algorithm, using pseudocode that input a temperature in degrees Celsius and convert it to
Fahrenheit. Include a declaration to the variables used.
Solution
DECLARE Celsius AS REAL
DECLARE Fahrenheit AS REAL
OUTPUT "Enter a temperature in Celsius: "
INPUT Celsius
Fahrenheit ← 1.8 * Celsius + 32
OUTPUT "The Temperature in Fahrenheit is ", Fahrenheit

Problem 11

Write an algorithm, using pseudocode to calculate the area of a rectangle. Your output should look
like this:

Solution
PRINT("Enter length: ")
INPUT Length
PRINT("Enter breadth: ")
INPUT Breadth
PRINT("Length = ",Length, " Breadth = ", Breadth)
Area ← Length * Breadth
PRINT("Area of Rectangle is = ",Area)

www.mahmoudmoussa.net 3
Mr. Mahmoud Moussa IGCSE CS 0984

Problem 12

Write an algorithm, using pseudocode to calculate the square and cube of a number using *
operator. Typical output is shown.

Solution
PRINT ("Enter the number: ")
INPUT Num
Square ← Num * Num
Cube ← Num * Num * Num
PRINT("Square of a Number = ",Num, " is ",Square)
PRINT("Cube of a Number = ",Num, " is ",Cube)

Problem 13

Write an algorithm, using pseudocode to read the weight of an object in grams and display its
weight in kilograms and grams, respectively. Typical output is shown.

Solution
PRINT("Enter the Weight of Object in grams: ")
INPUT Weight1
PRINT("Weight of Object = ",Weight1," grams")
Weight2 ← Weight1 DIV 1000 //Calculate No of kg
Weight3 ← Weight1 MOD 1000 //Calculate No of g
print("Weight of Object = ",Weight2, " kg and ",Weight3," g")

Problem 14

Write an algorithm, using pseudocode to reverse a four-digit number using MOD and DIV operators.
Typical output is shown.

Solution
PRINT("Enter four-digit number: ")
INPUT Num
PRINT("Entered number is: ",Num)
R1 ← Num MOD 10
Q1 ← Num DIV 10
R2 ← Q1 MOD 10
Q2 ← Q1 DIV 10
R3 ← Q2 MOD 10
Q3 ← Q2 DIV 10
R4 ← Q3 MOD 10
PRINT("Reverse of ",Num," is: ",R1," ",R2," ",R3," ",R4)

www.mahmoudmoussa.net 4
Mr. Mahmoud Moussa IGCSE CS 0984

Problem 15

Write an algorithm, using pseudocode that initializes an integer variable N with the value 5814 and
then uses the quotient and remainder operators to extract and print each digit of N.
The output should look like this: N = 5814 The digits of N are:
5
8
1
4
Solution
N ← 5814
OUTPUT ("N = " , N)
OUTPUT ("The digits of N are ")
OUTPUT(INT(N / 1000))
N ← N MOD 1000
OUTPUT(INT(N / 100))
N ← N MOD 100
OUTPUT(INT(N / 10))
N ← N MOD 10
OUTPUT(N)

Problem 16

Write an algorithm, using pseudocode that inputs one number consisting of five digits from the
user, separates the number into its individual digits and prints the digits separated from one another
by one space each. For example, if the user types in the number 42339, the program should print:
4 2 3 3 9
Solution
PRINT("Enter five digit integer: ")
INPUT Num
Digit1 ← INT(Num / 10000)
Digit2 ← INT(Num MOD 10000 / 1000)
Digit3 ← INT(Num MOD 10000 MOD 1000 / 100)
Digit4 ← INT(Num MOD 10000 MOD 1000 MOD 100 / 10)
Digit5 ← Num MOD 10000 MOD 1000 MOD 100 MOD 10
PRINT(Digit1," ", Digit2," ", Digit3," ", Digit4," ", Digit5)

www.mahmoudmoussa.net 5

You might also like