Algorithms and flowcharts for various control structures including converting height from centimeters to feet and inches, swapping two numbers using temporary and without temporary variables, checking if a year is a leap year, and evaluating input grades. Each problem includes an algorithm and a flowchart for easy understanding.
Download Lab Exercise: Algorithms & Flowcharts for Sequence & Selection Control Structures and more Lab Reports Physics in PDF only on Docsity!
LABORATORY EXERCISE NO. 3: SEQUENCE AND SELECTION CONTROL STRUCTURES
Practice.
Design an algorithm and flowchart to read height in centimeters and convert to feet and inches. Algorithm Flowchart
Start
Read height (H) in centimeters
Compute height in Feet (Ft) as Ft= H/30.48cm
Compute height in Inches (In) as In= H/2.54cm
Write (Display) height in Ft and In
Stop Start Read height Ft = H /30.48cm In = H/2.54cm Write height in Ft and In
Design an algorithm and flowchart to swap two numbers using temporary variable. Algorithm Flowchart
Start
Read NUM1 and NUM
Set Temporary Number as TEMP=NUM
Set NUM1 as NUM1=NUM
Set NUM2 as NUM2=TEMP
Write (Display) NUM1 and NUM 2
Stop Start Read NUM1 and NUM TEMP = NUM NUM1 = NUM NUM2 = TEMP Write NUM1 and NUM
Design an algorithm and flowchart to check whether the input year is a leap year or not. Algorithm Flowchart
Start
Read Year (A)
If input year (A) is divisible by 4 Write (Display) Leap Year
Else Write Not
Stop Start Read A True (^) False A is divisible by 4? Write Leap Year Write^ Not
Design an algorithm and flowchart to evaluate the input grade or scores if its grade A, B,C, D, or E. A: 95 ā 100 B: 90 ā 94 C: 80 ā 89 D: 70 ā 79 E: 69 and below Algorithm Flowchart
Start
Read Input Grades
If input grades is less than or equal to 69 Write E
End if
If input grades is greater than 69 and less than 80 Write D
End if
If input grades is greater than 79 and less than 90 Write C
End if
If input grades is greater than 89 and less than 96 Write B
End if
If input grades is greater than 94 and less than 100 Write A