Sum of N numbers

    Last updated November 30, 2026

    Add the integers from 1 through n. If n is less than 1, the sum is 0 and the loop does not run. FlowSimp is completely free to use — no sign-up required.

    See the flowchart

    What does the flowchart look like?

    Ready to draw?

    No signup. Opens instantly in your browser.

    See the flowchart

    What is the matching code?

    Pseudocode

    read n
    if n < 1 then sum = 0
    else
      sum = 0
      i = 1
      while i <= n
        sum = sum + i
        i = i + 1

    Python

    def sum_to(n):
        if n < 1:
            return 0
        total = 0
        i = 1
        while i <= n:
            total += i
            i += 1
        return total

    C

    int sum_to(int n) {
      int total = 0, i;
      if (n < 1) return 0;
      for (i = 1; i <= n; i++) total += i;
      return total;
    }
    • This adds 1 through n. It does not read n separate values from the user.
    • For n = 3 the additions are 1, then 2, then 3, and the total is 6.