Skip to content

Digit count

Pascal recursion over digits

Flowchart (ISO 5807)

YesNoStartInput nn < 10digits = 1digits = 1 + digits(n div 10)EndFigure 1 — digits

Source code

Pascal
function digits(n: integer): integer;
begin
  if n < 10 then
    digits := 1
  else
    digits := 1 + digits(n div 10);
end;

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

Language
Pascal
Constructs
recursion over digits
Topic
Recursion
Formats
Word, Visio, draw.io, PDF, SVG

Related examples