• Embed Doc
  • Readcast
  • Collections
  • CommentGo Back
Download
 
N
ATIONAL
U
NIVERSITY
 
OF
C
OMPUTER 
& E
MERGING
S
CIENCES
ARACHI
C
AMPUS
I
NTRODUCTION
 
TO
C
OMPUTERS
(CS-102)T
OPIC
: A
LGORITHM
& F
LOWCHART
A
SSIGNMENT
# 2SOLUTIONQuestion #1:
Draw a flowchart to add up all odd numbers between 0 and 100. Beforeending, print the result of calculation.STEP 1: Initialize n by 1 and sum by 0STEP 2: Add value of n in sumSTEP 3: Check;a)if n is less than 99 theni)Add 2 in value of nii)Move to Step 2 b)otherwisei)Move to Step 4STEP 4: Print ‘Sum of all odd numbers between 0 and 100 is:’ sumSTEP 5: Stop
Question #2:
Write the logical steps (pseudo-code) to calculate and print the totalnumber of students receiving 86 and above marks in the final examination. The classstrength is 20. Input of each student includes only marks ranging from 0 to 100. Draw aflowchart on the logical steps deduced.STEP 1: Initialize total_students by 0, marks by 0, strength by 1STEP 2: Print ‘Please enter marks for student #’, strengthSTEP 3: Read value in marksSTEP 4: Check;(a)if (strength is less than or equal to 20) theni)Move to Step 5(b)otherwiseii)Move to Step 7STEP 5: Check;(a)if (marks are less than 0) or (marks are greater than 100) theni)Move to Step 2(b)otherwiseii)Move to Step 6STEP 6: Check;(a)if (marks are greater than or equals to 86) theni)Add 1 in value of total_studentsii)Add 1 in strengthiii)Move to Step 2(b)otherwisei) Add 1 in strengthii)Move to Step 2STEP 7: Print ‘Total students who scored above or equal to 86 marks are:’ total_studentsSTEP 8: Stop
 
Question #3:
Write the logical steps (pseudo-code) to print the average age of allstudents in a class (class strength is not known). The input is name and age of eachstudent. To continue for the next input ask the user, answered as either yes or no. Draw aflowchart on the logical steps deduced.STEP 1: Initialize total_students by 0, total_age by 0, avg_age by 0, age by 0, name by““, continue by ‘y’STEP 2: Print ‘Do you want to enter the data of students, please enter 
y
for yes and
n
for no’STEP 3: Read value in continueSTEP 4: Check;(b)if (continue is equal to ‘
y
’) theni)Move to Step 5(b)otherwiseii)Move to StepSTEP 5: Print ‘Enter name and age of student’STEP 6: Read value in name, ageSTEP 7: Check;(a)if (age are less than 0) theni)Move to Step 5(b)otherwiseii)Move to Step 8STEP 8: Add 1 in total_studentsSTEP 9: Add age in total ageSTEP 10: Move to Step 2STEP 11: Divide tota_age by total_students and assign the result in avg_ageSTEP 12: Print ‘Average age of students who are:’ total_students ‘ in strength is:’,avg_ageSTEP 13: Stop
Question #4:
Draw a flowchart for the logical steps (pseudo-code) to find out whether agiven triangle ABC is a right-angle triangle. Assume that the sides of the triangle aresupplied as input. Print the answer as ‘yes’ or ‘no’.STEP 1: Initialize side1, side2, side3 by 0 and sq_side1, sq_side2, sq_side3 by 0STEP 2: Print ‘Enter the three sides’STEP 3: Read value in side1, side 2, side3STEP 4: Perform square operation on three sides:(a)Perform multiplication of side1 with itself and assign the result in sq_side1(b)Perform multiplication of side2 with itself and assign the result in sq_side2(c)Perform multiplication of side3 with itself and assign the result in sq_side3STEP 5: Check;(a)if (sq_side1 is equal to sum of sq_side2 and sq_side3) theni)Move to Step 6(i)(b)otherwise check;
 
1)if (sq_side2 is equal to sum of sq_side1 and sq_side3) theni)Move to Step 6(i)(c)otherwise check 1)if (sq_side3 is equal to sum of sq_side1 and sq_side2) theni)Move to Step 6(i)(d) otherwise1)Move to Step 6(iii)STEP 6:i)Print ‘Yes it’s a right angle triangle’ii) Move to Step 7iii)Print ‘No it is not a right angle triangle’STEP 7: Stop
Question #5:
Draw a flowchart for the logical steps (pseudo-code) to find out whether agiven quadrilateral ABCD is a rectangle. Assume that all the four angles and sides of thequadrilateral are supplied as input. Print the answer as ‘yes’ or ‘no’.STEP 1: Initialize angle1, angle2, angle3, angle4, side1, side2, side3 and side4 by 0STEP 2: Print ‘Enter the four sides’STEP 3: Read value in side1, side 2, side3, side 4STEP 4: Print ‘Enter the four angles’STEP 5: Read value in angle1, angle2, angle3, angle4STEP 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) theni)Move to Step 7(b)otherwisei)Move to Step 8(iii)STEP 7: Check;(a)if (side1 is equal to side2) and (side3 is equal to side4) theni)Move to Step 8(i)(b)otherwise check;1) if (side1 is equal to side3) and (side2 is equal to side4) theni)Move to Step 8(i)(c)otherwise check;1) if (side1 is equal to side4) and (side2 is equal to side3) theni)Move to Step 8(i)(d)otherwise1)Move to Step 8(iii)STEP 8:i)Print ‘Yes it’s a rectangle’ii)Move to Step 9iii)Print ‘No it is not a rectangle’STEP 9: Stop
of 00

Leave a Comment

You must be to leave a comment.
Submit
Characters: ...
You must be to leave a comment.
Submit
Characters: ...