0% found this document useful (0 votes)
28 views21 pages

L1F24BSSE0145

Uploaded by

abdullshahbaz2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views21 pages

L1F24BSSE0145

Uploaded by

abdullshahbaz2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 21

Introduction to Computing

Lab 05
Topic Flowgorithm
Flowgorithm
 Iterative Solutions
o Loops
Objective
 For
 While
 Do-while
Looping using While
Looping using For
Factorial of a number
Lab task
Task1: Distance Calculator

The distance a vehicle travels can be calculated as follows:


distance = speed * time
For example, if a train travels 40 miles per hour for 3 hours, the distance traveled is 120
miles.
Draw a flowchart that asks the user for the speed of a vehicle (in miles per hour) and how
many hours it has traveled. The program should then use a loop to display the distance the
vehicle has traveled for each hour of that period.

Here is an example of the output:

What is the speed of the vehicle in mph? 40


How many hours has it traveled? 3
Hour Distance Traveled
--------------------------------
1 40
2 80
3 120

Input Validation: Do not accept a negative number for speed and do not accept any value
less than 1 for time traveled.
Task 2: Positive and Negative Number Counter

Draw a flowchart that asks the user to enter numbers as many as he wants till he presses
the magic number 123. Count all the numbers that are positive, zero, and negative.

Sample Output:
Enter Number: 12
Enter Again: 122
Enter Again: -33
Enter Again: 67
Enter Again: -34
Enter Again: 0
Enter Again: -5
Enter Again: 0
Enter Again: 123

Results:
Positive Count: 3
Zero Count: 2
Negative Count: 3
Task 3: Sum of all Digits

Draw a flowchart that asks a user to enter a decimal number and then display the sum of all
digits present in that number
Sample Output:

Enter Number: 6782


Sum of Digits: 23
Task 4: Passcode Validation

In an application, the user has to enter his/her valid passcode. A valid passcode must
contain less than 5 digits at most 4 digits, also 0 digit must not be part of the number
entered. Draw a flowchart that can check whether the entered passcode is valid or not by
counting the total number of digits entered and display it.
Sample Input:
Enter your passcode (should be non-zero and less than 5): 551

Sample Output:
Passcode is invalid! Digit Count: 3! Enter again: 5512
Passcode Valid
Task 5: Fibonacci Series

The number or arrangement of petals on a flower are in such a way that each number adds
the previous consecutive number to find the next number in the series. This series is
Fibonacci series. Write a program that takes the number of terms in this series and print it.

Sample Input:

Sample Output:
Task 6: Salary Calculator

Draw a flowchart that calculates how much a person would earn over some time if his or her
salary is 1000 the first day and 2000 the second day and continues to double each day. The
program should ask the user for the first day's salary and total number of days. Display a
table showing how much the salary was for each day, and then show the total pay at the
end of the period. The output should be displayed in the total amount.

Input Validation: Do not accept a number less than 1 for the salary of the first day and the
number of days worked.

Sample Output:
Enter the salary for the first day: 1000
Enter the number of days: 5

Day Amount Earned


--------------------------------------
1 1000
2 2000
3 4000
4 8000
5 16000

Total salary for 5 days = 31000


Task 7: Fitness Tracker Step Counter

You are creating a fitness tracker that tracks how many steps a user takes each day. The
system should:

1. Prompt the user to input their step goal for the day.
2. Continuously ask the user to input the number of steps they have taken.
3. Stop when the user’s total steps for the day reach or exceed the goal.
4. Display a message congratulating the user once the goal is reached.

Steps for a loop:

1. Input the step goal.


2. Use a while loop to keep asking for the number of steps taken.
3. Stop and display a message once the total number of steps reaches or exceeds the
goal.
Task 8: Min, Max, Average Calculator
Draw a flowchart that asks the user to enter multiple integer numbers. The input should
end when the user enters 0. The program should then calculate the sum, average, maximum
and minimum from the entered numbers.
Example 1:
Input: 59 72 -3 201 632 0
Output:
Sum = 961
Average = 192.2
Maximum = 632
Minimum = -3

Example 2:
Input: 0
Output:
Sum = 0
Average = 0
Maximum = 0
Minimum = 0

Home Task
Task 8: Odds and Squares

Draw a flowchart that uses while loops to perform the following steps:

 Prompt the user to input two integers: firstNum and secondNum


(firstNum must be less than secondNum).
 Output all odd numbers between firstNum and secondNum.
 Output the sum of all even numbers between firstNum and
secondNum.
 Output the numbers and their squares between 1 and 10.
 Output the sum of the square of the odd numbers between firstNum
and secondNum.

You might also like