Pseudocode Guide 9618
Pseudocode Guide 9618
Pseudocode Guide
Commenting:
//Program made by Ali.
Variable:
The value of variable can change throughout the execution of a
program.
Constant:
Its value does not change throughout the execution of a
program.
Constant Declaration:
CONSTANT pi = 3.14
CONSTANT price = 25
OUTPUT Statement:
OUTPUT “My name is Ali.”
price = 25
OUTPUT “The price is:”, price
INPUT Statement:
INPUT num
INPUT name
Assignment Statement:
It is a statement where you assign a value to a variable. It can
be identified by an equals to “=” sign.
price = 25
sum = num1 + num2
area = 3.14 * radius * radius
Mathematical Operators:
Addition: +
Subtraction: -
Multiplication: *
Division: /
Exponent: ^
Group: ()
Comparison Operators:
Less than: <
Less than and equals to: <=
Greater than: >
Greater than and equals to: >=
Equals to: =
Not equals to: <>
Solution:
OUTPUT “Enter a number:”
INPUT num
IF num > 0
THEN OUTPUT “Positive”
ELSE IF num < 0
THEN OUTPUT “Negative”
ELSE OUTPUT “Zero”
ENDIF
ENDIF
Example:
Q. Write pseudocode for a program that inputs a number from
the user and print whether the number is positive, negative or
a zero.
Solution:
OUTPUT “Enter a number:”
INPUT num
CASE num OF
> 0 : OUTPUT “Positive”
< 0 : OUTPUT “Negative”
OTHERWISE OUTPUT “Zero”
ENDCASE
Task for Student:
Q. Write pseudocode for a program that inputs the percentage
of the student and then print his grade according to the
following criteria:
FOR Loop:
Basic Structure:
FOR variable = starting_value TO ending_value
Body of the loop (Any code that needs repetition)
NEXT variable
Example:
FOR a = 1 TO 10
OUTPUT “Ali”
NEXT a
Task for Student:
Q. Write pseudocode to input the name of the user and print it
ten time.
Example:
Q. Write a program to input numbers from the user and print
them. The program to stop when the user enter 0 as an input.
Solution:
REPEAT
OUTPUT “Enter a number or 0 to stop:”
INPUT num
OUTPUT “You entered:”, num
UNTIL num = 0
Solution:
a=0
REPEAT
OUTPUT “Enter a number:”
INPUT num
OUTPUT “You entered:”, num
a=a+1
UNTIL a = 25