Professional Documents
Culture Documents
Question #2: Write the logical steps (pseudo-code) to calculate and print the total
number of students receiving 86 and above marks in the final examination. The class
strength is 20. Input of each student includes only marks ranging from 0 to 100. Draw a
flowchart on the logical steps deduced.
STEP 1: Initialize total_students by 0, marks by 0, strength by 1
STEP 2: Print ‘Please enter marks for student #’, strength
STEP 3: Read value in marks
STEP 4: Check;
(a) if (strength is less than or equal to 20) then
i)Move to Step 5
(b)otherwise
ii)Move to Step 7
STEP 5: Check;
(a)if (marks are less than 0) or (marks are greater than 100) then
i)Move to Step 2
(b)otherwise
ii)Move to Step 6
STEP 6: Check;
(a)if (marks are greater than or equals to 86) then
i)Add 1 in value of total_students
ii)Add 1 in strength
iii)Move to Step 2
(b)otherwise
i) Add 1 in strength
ii)Move to Step 2
STEP 7: Print ‘Total students who scored above or equal to 86 marks are:’ total_students
STEP 8: Stop
Question #3: Write the logical steps (pseudo-code) to print the average age of all
students in a class (class strength is not known). The input is name and age of each
student. To continue for the next input ask the user, answered as either yes or no. Draw a
flowchart on the logical steps deduced.
Question #4: Draw a flowchart for the logical steps (pseudo-code) to find out whether a
given triangle ABC is a right-angle triangle. Assume that the sides of the triangle are
supplied as input. Print the answer as ‘yes’ or ‘no’.
Question #5: Draw a flowchart for the logical steps (pseudo-code) to find out whether a
given quadrilateral ABCD is a rectangle. Assume that all the four angles and sides of the
quadrilateral are supplied as input. Print the answer as ‘yes’ or ‘no’.
STEP 1: Initialize angle1, angle2, angle3, angle4, side1, side2, side3 and side4 by 0
STEP 2: Print ‘Enter the four sides’
STEP 3: Read value in side1, side 2, side3, side 4
STEP 4: Print ‘Enter the four angles’
STEP 5: Read value in angle1, angle2, angle3, angle4
STEP 6: Check;
(a)if (angle1 is equal to 90) and (angle2 is equal to 90) and (angle3 is equal to 90) and
(angle4 is equal to 90) then
i)Move to Step 7
(b)otherwise
i)Move to Step 8(iii)
STEP 7: Check;
(a)if (side1 is equal to side2) and (side3 is equal to side4) then
i)Move to Step 8(i)
(b)otherwise check;
1) if (side1 is equal to side3) and (side2 is equal to side4) then
i)Move to Step 8(i)
(c)otherwise check;
1) if (side1 is equal to side4) and (side2 is equal to side3) then
i)Move to Step 8(i)
(d)otherwise
1)Move to Step 8(iii)
STEP 8:
i)Print ‘Yes it’s a rectangle’
ii)Move to Step 9
iii)Print ‘No it is not a rectangle’
STEP 9: Stop
Question #6: Draw a flowchart for the logical steps that converts a number from base 10
to base 2 by using the division-remainder technique.
Question #7: Write the logical steps (pseudo-code) and draw a flowchart that takes two
input values x and n, then find the value of xn using successive multiplication.
Note: For n = 0, x0 = 1
Question #8: Write the logical steps (pseudo-code) and draw a flowchart that takes two
input values x and y, then find the GCD (greatest-common divisor) for the two input
values.
Question #9: Assume a shelf of 10 rows (each row having one column). Each row is
storing a student file identified (labeled) by his/her student identification number (SID).
The files are placed in the shelf in an unordered manner. Write the logical steps (pseudo-
code) and draw a flowchart that orders (sorts) the files in the shelf in descending order.
Step1: Initialize the variables representing rows on shelf as; A1, A2, A3, A4, A5, A6, A7,
A8, A9, A10 by 0
Step2: Use i, j to represent each row and Ai / Aj to represent each SID (where i and j
cover the range from 1 to 10)
Step3: Inititalize i by 1
Step4: Check;
(a) If(i is less than or equal to 10) then
i) Read Ai
ii) Add 1 in i
iii) Move to Step 4(a)
Step5: Initialize i by 1 and j by 2
Step6: Check;
(a) If (i is less than 10) then
i) if(j is less than or equal to 10) then
1) Check; if(Ai is less than Aj) then
1(i) Assign Ai to temp
1(ii) Assign Aj to Ai
1(iii) Assign temp to Aj
2)Add 1 in j
3) Move to Step 6(a)(i)
ii)otherwise;
1) Add 1 in i
2) Initialize j by adding 1 in i
3) Move to Step 6(a)
(b)Otherwise;
i)Print ‘ The rows on the shelf has files of each SID in descending order’
ii) Move to Step 7
Step 7: Stop
-----------------------------------------------The
End--------------------------------------------------