Introduction to Computing
Lab 04
Topic Flowgorithm
Flowgorithm
Iterative Solutions
o Loops
Objective
For
While
Do-while
Looping using While
Looping using For
Factorial of a number
Lab tasks
Task 1: Sum of First N Natural Numbers
Description: The user wants to find the sum of the first N natural numbers.
The system should:
1. Input a number N.
2. Use a for loop to sum all numbers from 1 to N.
3. Display the sum.
Steps:
1. Input N.
2. Use a for loop to iterate from 1 to N, adding each value to a sum.
3. Display the total sum.
Task 2: Sum of Odd Numbers
Description: The user wants to find the sum of all odd numbers from 1 to N.
The system should:
1. Input a number N.
2. Use a for loop to sum all odd numbers from 1 to N.
3. Display the sum.
Steps:
1. Input N.
2. Initialize a sum variable to 0.
3. Use a for loop to check each number from 1 to N; if the number is odd, add it to the sum.
4. Display the sum.
Task 3: Print the Multiples of 5 from 1 to N
Description: The user wants to print all multiples of 5 up to N.
The system should:
1. Input a number N.
2. Use a for loop to print all multiples of 5 from 1 to N.
Steps:
1. Input N.
2. Use a for loop to check every number from 1 to N. If the number is divisible by 5, print it.
Task 4: Multiplication Table Generator
The user wants to generate a multiplication table for a specific number. The system should:
1. Input a number for which the user wants the multiplication table.
2. Use a for loop to display the multiplication table for that number up to 10.
Steps for a for loop:
1. Input the number.
2. Use a for loop to multiply the number by values from 1 to 10.
3. Display the results.
Task 5: Calculate Average Monthly Temperature
A weather station records the temperature for each day of the month. The system should:
1. Ask the user for the number of days in the month.
2. For each day, input the temperature.
3. After all temperatures are entered, calculate and display the average temperature for the
month.
Steps for a for loop:
1. Input the number of days.
2. Use a for loop to collect the temperature for each day.
3. Calculate and display the average temperature.