Department of Computer Science
BS Computer Science
NASTP Institute of Information Technology
Submitted By: Salar Ahmad Hasan
Submitted To: Ms. Iqra Siddique
Semester: I
Session: Spring – 2025 to 2029
Subject: Programming Fundamentals Lab
Date of submission: 06-03-2025
Question 01: Write the pseudo-code, flowchart, and algorithm for the
following problems:
a) For a program that checks whether a given number is even or odd.
b) To calculate the average of three numbers.
c) Find the sum of the first 10 natural numbers.
d) For a program that calculates the area of a circle.
e) Withdraw money using the ATM machine.
f) To represent a program that converts Fahrenheit to Celsius.
Checking whether number is Even or Odd
Algorithm
Start
Ask the user to enter a number.
Check if the number can be divided evenly by 2.
If yes, display "The number is Even."
Otherwise, display "The number is Odd."
End
Pseudo-Code
START
INPUT number
IF number MOD 2 == 0 THEN
OUTPUT "The number is even."
ELSE
OUTPUT "The number is odd."
ENDIF
END
Flowchart
Start Input Num
Calculating the Average of Three Numbers
Algorithm
1. Start If Num
No Yes Output
Output2.“Odd” %2==0
Ask the user to enter three numbers. “Even”
End
3. Add the three numbers together.
4. Divide the total by 3 to get the average.
5. Display the average.
6. End
Pseudo-Code
START
INPUT num1, num2, num3
sum = num1 + num2 + num3
average = sum / 3
OUTPUT "The average is", average
END
Flowchart
Input num1,
Start
num2, num3
Sum=num1+num2+num3
Avg=Sum/3
Sum of the First 10 Natural Numbers
End
Algorithm Output Avg
1. Start
2. Set a total sum to zero.
3. Add the numbers from 1 to 10 one by one to the total sum.
4. Display the total sum.
5. End the program.
Pseudo-Code
START
sum = 0 // Initialize sum to 0
FOR i FROM 1 TO 10 DO // Loop from 1 to 10
sum = sum + i // Add current number i to sum
ENDFOR
OUTPUT "The sum is", sum // Display the sum
END
Flowchart
Start Declare i=1, sum=0
sum= sum + i
End
i=i+1
Calculating Area of a Circle
Output sum No If i <= 10 Yes
Algorithm
1. Start
2. Ask the user to enter the radius of the circle.
3. Multiply the radius by itself, then multiply by 3.1416 (π).
4. Display the area of the circle.
5. End.
Pseudo-Code
START
INPUT radius
area = 3.14 * radius * radius // Using 3.14 as an approximation of π
OUTPUT "The area of the circle is", area
END
Flowchart
Start
Input R
Area =3.14*R*R
Output Area
ATM Withdrawal Process
Algorithm
Start the
Insert your ATM card into the machine.End
Enter your PIN.
If the PIN is correct:
1. Choose the "Withdraw" option.
2. Enter the amount you want to withdraw.
3. If you have enough money in your account:
a. The ATM will give you the cash.
b. It will print a receipt if needed.
4. If there is not enough money, it will show "Insufficient funds."
If the PIN is incorrect, it will show "Invalid PIN."
5. Take your card and end the transaction.
Pseudo-Code
START
VERIFY account
IF account is invalid THEN
OUTPUT "Transaction failed: Invalid account"
END
ENDIF
INPUT withdrawalAmount
IF withdrawalAmount exceeds balance OR is not a valid denomination THEN
OUTPUT "Transaction failed: Insufficient funds or invalid amount"
END
ENDIF
Deduct withdrawalAmount from accountBalance
DISPENSE cash
OUTPUT "Transaction successful. Please take your cash."
END
Flowchart
Start Insert Debit/Credit Card
Is Card
Yes No
Valid
Insert Pin Code Hold the card
Enter Withdrawal End
amount
Sufficient
funds on OUTPUT
No
account? "Transaction failed:
Insufficient funds or
invalid amount"
Yes
Fahrenheit to Celsius Conversion
Release money End
Algorithm
1. Start
2. Ask the user to enter a temperature in Fahrenheit.
3. Subtract 32 from the Fahrenheit value.
4. Multiply the result by 5, then divide by 9.
5. Display the temperature in Celsius.
6. End
Pseudo-Code
:
START
INPUT Fahrenheit
Celsius = (Fahrenheit - 32) * 5 / 9
OUTPUT "The temperature in Celsius is", Celsius
END
Flowchart
Start Input F
Cel=(F-32) * 5/9
Output Cel
End