1. Find whether there is a number 7 in an array of list containing 10 numbers.
DECLARE numbers: ARRAY [0:9] of INTEGER
DECLARE found : BOOLEAN
DECLARE i : INTEGER
// Assigning values to the array
OUTPUT "Enter these 10 values in order 27, 19, 36, 42, 16, 7, 21, 16, 55, 72"
FOR i ← 0 TO 9
OUTPUT "Enter next value "
INPUT numbers[i]
Next i
// Set initial value of found to FALSE
found ← FALSE
// Search for the number 7 in the array
FOR i ← 0 TO 9
IF numbers[i] = 7 THEN
found ← TRUE
ENDIF
NEXT i
// Output result based on the value of 'found'
IF found THEN
OUTPUT "7 is in the list."
ELSE
OUTPUT "7 is not in the list."
ENDIF
In Python declaring an array, populate and display:
1D
my_list = [10, 20, 30, 40]
print(my_list[0]) # Output: 10
print(my_list[1]) # Output: 20
2D
MyTable = [[27, 31, 17], [19, 67, 48],[36, 98, 29],[42, 22, 95], [16, 35, 61], [89, 46, 47], [21, 71, 28], [16, 23, 13], [55, 11, 77] [34,
76, 21]
Store marks of 3 students in 3 subjects
# Creating a 2D array
marks = [
[75, 80, 90], # Student 1
[60, 65, 70], # Student 2
[88, 85, 92] # Student 3
]
# Accessing elements
print("Marks of Student 1 in Subject 2:", marks[0][1])
print("Marks of Student 3 in Subject 3:", marks[2][2])
OUTPUT
Marks of Student 1 in Subject 2: 80
Marks of Student 3 in Subject 3: 92
Linear Search Algorithm
DECLARE Numbers : ARRAY[1:10] OF INTEGER
DECLARE SearchValue, i : INTEGER
DECLARE Found : BOOLEAN
// Input 10 numbers into the array
FOR i ← 1 TO 10
OUTPUT "Enter number ", i
INPUT Numbers[i]
NEXT i
// Ask for value to search
OUTPUT "Enter value to search for:"
INPUT SearchValue
// Initialize Found as FALSE
Found ← FALSE
// Linear Search
FOR i ← 1 TO 10
IF Numbers[i] = SearchValue THEN
OUTPUT "Value found at position ", i
Found ← TRUE
BREAK
ENDIF
NEXT i
// If value not found
IF Found = FALSE THEN
OUTPUT "Value not found in the array."
ENDIF
Bubble sort Algorithm 10 numbers in Ascending order
DECLARE Numbers : ARRAY[1:10] OF INTEGER
DECLARE Temp, i, j : INTEGER
// Input 10 numbers
FOR i ← 1 TO 10
OUTPUT "Enter number ", i
INPUT Numbers[i]
NEXT i
// Bubble sort in ascending order
FOR i ← 1 TO 9
// Passes: 9 total for 10 numbers
FOR j ← 1 TO 10 - i
IF Numbers[j] > Numbers[j + 1] THEN
// Swap the values
Temp ← Numbers[j]
Numbers[j] ← Numbers[j + 1]
Numbers[j + 1] ← Temp
ENDIF
NEXT j
NEXT i
// Output the sorted array
OUTPUT "Sorted numbers in ascending order:"
FOR i ← 1 TO 10
OUTPUT Numbers[i]
NEXT i
REPEAT………..UNTIL
REPEAT
OUTPUT "Enter your password (exactly 8 characters): "
INPUT Password
IF LENGTH(Password) <> 8 THEN
OUTPUT "Password must be exactly 8 characters. Try again."
ENDIF
UNTIL LENGTH(Password) = 8
WHILE…………DO
OUTPUT "Enter your password (exactly 8 characters): "
INPUT Password
WHILE LENGTH(Password) <> 8 DO
OUTPUT "Password must be exactly 8 characters. Try again."
OUTPUT "Enter your password (exactly 8 characters): "
INPUT Password
ENDWHILE
Use of WHILE DO and REPEAT UNTIL example for input numbers and get total until 9999.9 input to terminate the program.
Total 0
INPUT Value
WHILE Value <> 9999.9 DO
Total Total + Value
INPUT Value
ENDWHILE
OUTPUT Total
=================================================================
Value 0
Total 0
REPEAT
Total Total + Value
INPUT Value
UNTIL Value = 9999.9
OUTPUT Total
Calculate highest and lowest number from ten positive integers. (number between 0 and 100)
A←0
B←0
C ← 100
OUTPUT "Enter your ten values"
REPEAT
INPUT X
IF X > B
THEN B ← X
ENDIF IF X < C
THEN C ← X
ENDIF
A←A+1
UNTIL A > 10
OUTPUT B, C
=======================================================================================
Calculate highest and lowest number from ten positive integers. (Unlimited big number)
OUTPUT "Enter number 1:"
INPUT number
highest ← number
lowest ← number
count ← 1
REPEAT
count ← count + 1
OUTPUT "Enter number ", count, ":"
INPUT number
IF number > highest THEN
highest ← number
ENDIF
IF number < lowest THEN
lowest ← number
ENDIF
UNTIL count = 10
OUTPUT "The highest number is: ", highest
OUTPUT "The lowest number is: ", lowest
Calculate highest and lowest number from ten positive integers. (Unlimited big number)
OUTPUT "Enter number 1:"
INPUT number
highest ← number
lowest ← number
count ← 1
WHILE count < 10 DO
count ← count + 1
OUTPUT "Enter number ", count, ":"
INPUT number
IF number > highest THEN
highest ← number
ENDIF
IF number < lowest THEN
lowest ← number
ENDIF
ENDWHILE
OUTPUT "The highest number is: ", highest
OUTPUT "The lowest number is: ", lowest
a pseudocode algorithm using a REPEAT...UNTIL loop to:
Input marks repeatedly
Stop when the user enters 999
Then calculate and output the total, average, and number of marks entered (excluding 999)
Total ← 0
Count ← 0
REPEAT
INPUT Mark
IF Mark ≠ 999 THEN
Total ← Total + Mark
Count ← Count + 1
ENDIF
UNTIL Mark = 999
IF Count > 0 THEN
Average ← Total / Count
OUTPUT "Total marks: ", Total
OUTPUT "Average marks: ", Average
OUTPUT "Number of marks entered: ", Count
ELSE
OUTPUT "No marks entered."
ENDIF