Algorithm and Flowchart Examples: 10 Programs for Beginners
These are the ten programs that appear again and again in first-year programming labs and exams. For each one you get the algorithm in plain steps and the idea behind the flowchart, so you can draw it confidently.
Flowcharts · 2026-10-14 · 10 min read
Algorithm vs flowchart
An algorithm is the list of steps to solve a problem, written in plain language. A flowchart is the same steps drawn with standard symbols. Write the algorithm first; the flowchart is then just a matter of turning each step into a shape — inputs become parallelograms, calculations become rectangles and every "if" becomes a diamond.
1. Check whether a number is even or odd
- Start
- Read n
- If n mod 2 = 0, print "Even"
- Otherwise print "Odd"
- Stop
Flowchart idea: one decision diamond ("n mod 2 = 0?") with a Yes arrow to "Print Even" and a No arrow to "Print Odd", both joining at Stop.
2. Largest of three numbers
- Start
- Read a, b, c
- If a > b, then: if a > c the largest is a, else c
- Else: if b > c the largest is b, else c
- Print the largest
- Stop
Example: Largest of three numbers — nested decisions.
3. Factorial of a number
- Start
- Read n
- Set fact = 1 and i = 1
- While i ≤ n: fact = fact × i, then i = i + 1
- Print fact
- Stop
This is the first loop most students draw: the decision "i ≤ n?" sends the Yes arrow into the multiply step and back up, and the No arrow out to "Print fact".
Example: Factorial using a loop — note the arrow that goes back up.
4. Check for a prime number
- Start
- Read n
- Set i = 2
- While i × i ≤ n: if n mod i = 0, print "Not prime" and stop; else i = i + 1
- Print "Prime"
- Stop
Tip: Checking only up to the square root of n (i × i ≤ n) is enough, and examiners like to see it because it shows you understand why.
Example: Prime check with a square-root loop.
5. Sum of the first n natural numbers
- Start
- Read n
- Set sum = 0, i = 1
- While i ≤ n: sum = sum + i, i = i + 1
- Print sum
- Stop
6. Swap two numbers
- Start
- Read a, b
- temp = a, a = b, b = temp
- Print a, b
- Stop
No decision is needed — a straight line of process boxes. A popular follow-up is swapping without a third variable: a = a + b, b = a − b, a = a − b.
7. Leap year
- Start
- Read year
- If year is divisible by 400 → leap year
- Else if divisible by 100 → not a leap year
- Else if divisible by 4 → leap year
- Else → not a leap year
- Stop
Three chained decisions. The order matters: test 400 before 100, and 100 before 4.
8. Fibonacci series up to n terms
- Start
- Read n
- Set a = 0, b = 1, i = 1
- While i ≤ n: print a; next = a + b; a = b; b = next; i = i + 1
- Stop
9. Reverse a number
- Start
- Read n
- Set rev = 0
- While n > 0: digit = n mod 10; rev = rev × 10 + digit; n = n div 10
- Print rev
- Stop
Compare the reversed number with the original and you have the palindrome check.
10. Student grade calculator
- Start
- Read marks
- If marks ≥ 90 → Grade A
- Else if marks ≥ 75 → Grade B
- Else if marks ≥ 50 → Grade C
- Else → Fail
- Stop
Example: A ladder of decisions — each No arrow leads to the next test.
How to score full marks
- Use the right symbol for every step (see our guide to flowchart symbols).
- Label every arrow leaving a diamond.
- Initialise variables (sum = 0, fact = 1) in a process box before the loop.
- Keep the main flow vertical and draw loops on one side so arrows do not cross.
Generate any lab-program flowchart →
Frequently asked questions
What is the difference between an algorithm and a flowchart?
An algorithm is the step-by-step solution written in words; a flowchart shows the same steps as a diagram with standard symbols and arrows.
How do you show a loop in a flowchart?
With a decision (for example "i ≤ n?") whose Yes arrow goes through the loop body and back up to the decision, and whose No arrow leaves the loop.
Can AI draw a flowchart from my program?
Yes. Describe the program or paste the algorithm into AI Flowchart and it draws an editable flowchart with the correct symbols, which you can export for your lab record.