Pseudocode Practice Solutions
Pseudocode Practice Solutions
Input:
Output:
Solution example:
FindStudent(studentID)
STUDENT_IDS = [101, 203, 315, 432, 509]
STUD_ID = 0
input STUD_ID
function FIND_STUD(FIND_ID)
loop i from 0 to 4
if STUDENT_IDS[i] = FIND_ID
return 0
end if
end loop
return 0
end function
FIND_STUD(STUD_ID)
Write a pseudocode to sort the STUDENT_IDS array in ascending order using selection
sort.
Input:
PROCEDURE SortStudents()
DECLARE STUDENT_IDS AS ARRAY ← [203, 432, 315, 509, 101]
DECLARE n ← LENGTH(STUDENT_IDS)
FOR i FROM 0 TO n - 2 DO
minIndex = i
FOR j FROM i + 1 TO n - 1
IF STUDENT_IDS[j] < STUDENT_IDS[minIndex] THEN
minIndex = j
END IF
END FOR
IF minIndex ≠ i THEN
DECLARE temp = STUDENT_IDS[i]
STUDENT_IDS[i] = STUDENT_IDS[minIndex]
STUDENT_IDS[minIndex] = temp
END IF
END FOR
OUTPUT STUDENT_IDS
END PROCEDURE
Write a pseudocode to count how many students have passed a test. Passing scores
are stored in the SCORES array.
Input:
Output:
CountPassedStudents()
SCORES = [45, 78, 62, 55, 90]
passMark = 50
count = 0
Input:
Output:
FindMaxScore()
SCORES = [45, 78, 62, 55, 90]
DECLARE max = SCORES[0]
Input:
Output:
PROCEDURE FindMinScore()
SCORES = [45, 78, 62, 55, 90]
min = SCORES[0]
Problem:
First, sort the SCORES array in ascending order using selection sort. Then, write a
pseudocode function to check if a specific score exists in the array.
Input:
Output:
PROCEDURE SortAndSearch(score)
SCORES = [45, 78, 62, 55, 90]
n = LENGTH(SCORES)
*********************