Код IT
← Каталог

Pascal / Free Pascal — типовые программы — 10.3. Количество цифр в числе

Фрагмент из «Pascal / Free Pascal — типовые программы»: 10.3. Количество цифр в числе.

Pascal main.pas
program CountDigits;

var
  n: int64;
  cnt: integer;

begin
  ReadLn(n);
  if n = 0 then
    WriteLn(1)
  else
  begin
    cnt := 0;
    while n > 0 do
    begin
      cnt := cnt + 1;
      n := n div 10;
    end;
    WriteLn(cnt);
  end;
end.
program CountDigits;

var
  n: int64;
  cnt: integer;

begin
  ReadLn(n);
  if n = 0 then
    WriteLn(1)
  else
  begin
    cnt := 0;
    while n > 0 do
    begin
      cnt := cnt + 1;
      n := n div 10;
    end;
    WriteLn(cnt);
  end;
end.