Skip to content

Triangular number

Pascal sum accumulation

Flowchart (ISO 5807)

StartInput ns = 0i = 1, n, 1s = s + itriangular = sEndFigure 1 — triangular

Source code

Pascal
function triangular(n: integer): integer;
var i, s: integer;
begin
  s := 0;
  for i := 1 to n do
    s := s + i;
  triangular := s;
end;

The editor opens with this code — change it and the chart redraws.

Language
Pascal
Constructs
sum accumulation
Topic
Loops
Formats
Word, Visio, draw.io, PDF, SVG

Related examples