Page 36 - IT_V5.0_Class6
P. 36
Problem 5: Write an algorithm for deciding what to eat based on the time of day.
1. If the time is morning, eat breakfast.
2. Else if the time is afternoon, Eat lunch.
3. Else, Eat dinner.
Step 1: Start
Step 2: Input current time of day (morning, afternoon, or evening).
Step 3: IF the time is morning, THEN
Eat breakfast.
Step 4: ELSE IF the time is afternoon, THEN
Eat lunch.
Step 5: Else
Eat dinner.
Step 6: Stop
Repetition
This helps to make tasks easier and faster by repeating steps without having to write them out
multiple times. Repetition is often used in loops. A loop is a way to repeat a set of instructions.
Why Use Repetition?
Some reasons to use repetition are as follows:
Saves time: Instead of writing the same instructions over and over, you can write them once
and repeat them as needed.
Makes the algorithm shorter: This makes your algorithm easier to read and understand.
Handles large amounts of data: Repetition is helpful when you need to process many items,
like counting or calculating.
Problem 6: You want to make 3 sandwiches for lunch.
Step 1: Start
Step 2: Set a variable count= 1.
Step 3: Repeat the following steps until count reaches 3.
Make one sandwich.
Increase count by 1.
Goto Step 3
Step 4: End
Problem 7: Write an algorithm for giving water to 5 plants.
_____________________________________________________________________________________________________
_____________________________________________________________________________________________________
_____________________________________________________________________________________________________
_____________________________________________________________________________________________________
_____________________________________________________________________________________________________
_____________________________________________________________________________________________________
34 Information Technology (V5.0)-VI

