← All examples

Digit count

Pascal Loops

how many digits

Flowchart (ISO 5807)

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

Source code

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;