Flowchart Updated 12/2/2026

Sum of N Numbers Flowchart

Flowchart to find sum of n numbers: set sum = 0 and i = 1, add i to sum while i <= n, then print sum. With a trace table for n = 5, pseudocode, tested Python, C and Java code, and the n(n+1)/2 shortcut.

sum of n numbersflowchartloopsaccumulatorprogramming
9 nodes 9 connections

Study guide

Sum of N Numbers FlowchartStartRead nSet sum = 0Set i = 1i <= n?Set sum = sum + iSet i = i + 1Print sumEndYesNo
Sum of N Numbers Flowchart. Source: https://www.chartcraft.dev/examples/sum-of-n-numbers-flowchart

What the sum of first n natural numbers flowchart shows

A flowchart to find sum of n numbers uses an accumulator: a variable sum that starts at 0 and grows by one number on every pass of a loop. A counter i walks from 1 to n, and the loop stops when i passes n.

This running total pattern is everywhere: averages, scores, shopping baskets. Learn it once here.

Sum of first n natural numbers flowchart, step by step

  1. terminator StartOne Start terminator opens the flowchart.
  2. input/output Read nThe program reads how many numbers to add, n.
  3. process Set sum = 0The accumulator must start at 0, before the loop. Adding to a variable that was never set gives garbage in C.
  4. process Set i = 1The counter starts at the first number to add, 1.
  5. decision i <= n?The loop condition, tested before every pass. Yes means there is still a number to add; No means all n numbers are in.
  6. process Set sum = sum + iThe heart of the loop: add the current number to the running total.
  7. process Set i = i + 1Move the counter on, then go back up to the condition. Without this step the loop never ends.
  8. input/output Print sumAfter the loop, sum holds 1 + 2 + ... + n.
  9. terminator EndOne End terminator closes the flowchart.

Dry run: trace table for n = 5

Follow the flowchart with n = 5. Each row is one visit to the i <= n? diamond.

ii <= n?sum beforesum afterNext step
1Yes01Set i = 2
2Yes13Set i = 3
3Yes36Set i = 4
4Yes610Set i = 5
5Yes1015Set i = 6
6No1515Print sum (15)

Five passes add five numbers, and the sixth test ends the loop. Check: 5 x 6 / 2 = 15.

Sum of first n natural numbers pseudocode

Pseudocode
READ n
sum = 0
i = 1
WHILE i <= n
    sum = sum + i
    i = i + 1
ENDWHILE
PRINT "Sum =", sum

Sum of first n natural numbers in Python, C and Java

Python
n = int(input())

total = 0   # "sum" is a built-in name in Python
i = 1
while i <= n:
    total = total + i
    i = i + 1

print("Sum =", total)
C
#include <stdio.h>

int main(void) {
    int n;
    scanf("%d", &n);

    int sum = 0;
    int i = 1;
    while (i <= n) {
        sum = sum + i;
        i = i + 1;
    }

    printf("Sum = %d\n", sum);
    return 0;
}
Java
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();

        int sum = 0;
        int i = 1;
        while (i <= n) {
            sum = sum + i;
            i = i + 1;
        }

        System.out.println("Sum = " + sum);
    }
}
Input typed at the keyboard
5
Output of all three programs
Sum = 15

All three programs were compiled and run with the input 5 before this page was published, and they print exactly the output shown. The Python version names the accumulator total because sum is a built-in function in Python.

Mistakes examiners see most

  • Setting sum = 0 inside the loop. Then the total is wiped on every pass and the answer is just n. The initialisation boxes go above the diamond, never inside the loop.
  • Using i < n. With < the loop stops before adding n itself: for n = 5 it gives 10. The condition is i <= n.
  • Printing inside the loop. Print sum belongs on the No exit. Inside the loop it prints every partial total (1, 3, 6, 10, 15).
  • Returning the loop arrow to Set i = 1. The arrow from Set i = i + 1 must go back to the diamond. Going back to an initialisation step restarts the count forever. See the while loop flowchart.

Practice questions with worked answers

Q1 What does the flowchart print for n = 0?

Sum = 0. With i = 1 the first test 1 <= 0 is No, so the loop body never runs and sum keeps its starting value.

This is why the test sits above the body: a pre-test loop can run zero times.

Q2 Change the flowchart to add n numbers typed by the user instead of 1 to n.

Add an input box Read x at the top of the loop body and change the addition to Set sum = sum + x. The counter i now only counts how many numbers were read.

Pseudocode
READ n
sum = 0
i = 1
WHILE i <= n
    READ x
    sum = sum + x
    i = i + 1
ENDWHILE
PRINT "Sum =", sum
Q3 Use the formula n(n + 1) / 2 to check the loop for n = 100. Why might you still draw the loop?

100 x 101 / 2 = 5050, which is what the loop prints after 100 passes.

The formula only works for 1 to n. The loop pattern works for any list of numbers, which is why exams ask for it. The same flowchart with a for loop is equally correct.

Flowchart symbols used and why

SymbolShape to draw on paperWhere it appears hereWhy
TerminatorRounded boxStart and EndOne entry and one exit.
Input/outputParallelogramRead n and Print sumThey move data in or out of the program.
ProcessRectangleSet sum = 0, Set i = 1, Set sum = sum + i and Set i = i + 1Each changes a stored value and has one exit.
DecisionDiamondi <= n?A yes-or-no question with two labelled exits.
LoopA decision whose flow line returns to an earlier stepThe arrow from Set i = i + 1 back up to i <= n?Returning to the diamond repeats the body. The diamond is above the body, so this is a pre-test loop.
Flow lineArrowEvery arrowArrows give the order. Only the loop arrow points upward.

In the interactive diagram every step is a labelled card: the small word above each step names its kind (process, decision or data). When you draw this flowchart by hand, use the standard shapes in the table. The full list is on the flowchart symbols page.

Make your own version

Each link opens the editor with a prompt already filled in. Change the wording, then generate your own flowchart.

How can I use this flowchart?

Download the Sum of N Numbers Flowchart as a PNG or SVG, or open it in the studio to edit your own copy. To draw a similar flowchart from a description, use the flowchart generator; for notation and a step-by-step walkthrough, read how to make a flowchart; and browse more flowchart examples for related layouts.

Try the studio with your own description.

Type any system, process, or schema in plain English. ChartCraft will draw it in seconds.