]]> ]]>

Факториал в Cool

Пример для версий Cool 2008
class Main : IO is
  Main() begin
    out_string("Enter an integer greater-than or equal-to 0: ");

    let input: Integer := in_int(); in
      if input < 0 then
        out_string("ERROR: Number must be greater-than or equal-to 0\n")
      else
        out_string("The factorial of ").out_int(input);
        out_string(" is ").out_int(factorial(input))
      fi
    end
  end;

  factorial(num: Integer): Integer := if num = 0 then 1 else num * factorial(num - 1) fi;
end;

Комментарии

]]>

blog comments powered by Disqus

]]>

Работа программистам