Basic Programming Algorithms Explained
Basic Programming Algorithms Explained
BS Computer Science
NASTP Institute of Information Technology
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
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
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
sum= sum + i
End
i=i+1
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
END
Flowchart
Is Card
Yes No
Valid
Insert Pin Code Hold the card
Sufficient
funds on OUTPUT
No
account? "Transaction failed:
Insufficient funds or
invalid amount"
Yes
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