Skip to content

Digit count

Pascal how many digits

Flowchart (ISO 5807)

YesNoYesNoStartInput nc = 0n = 0c = 1n ≠ 0c = c + 1n = n div 10digits = cEndFigure 1 — digits

Source code

Pascal
function digits(n: integer): integer;
var c: integer;
begin
  c := 0;
  if n = 0 then
    c := 1;
  while n <> 0 do
  begin
    c := c + 1;
    n := n div 10;
  end;
  digits := c;
end;

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

Language
Pascal
Constructs
how many digits
Topic
Loops
Formats
Word, Visio, draw.io, PDF, SVG

Related examples