]]> ]]>

Квадратное уравнение в Seed7

Пример для версий Seed7 2012-01-01
$ include "seed7_05.s7i";
  include "float.s7i";
  include "math.s7i";

const proc: main is func
local
    var float: a is 0.0;
    var float: b is 0.0;
    var float: c is 0.0;
    var float: d is 0.0;
begin
    readln(a);
    if a = 0.0 then
        writeln("Not a quadratic equation.");
    else
        readln(b);
        readln(c);
        d := b ** 2 - 4.0 * a * c;
        if d = 0.0 then
            writeln("x = " <& (-b / 2.0 / a));
        else
            if d > 0.0 then
                writeln("x1 = " <& ((-b + sqrt(d)) / 2.0 / a));
                writeln("x2 = " <& ((-b - sqrt(d)) / 2.0 / a));
            else
                writeln("x1 = (" <& (-b / 2.0 / a) <& "," <& (sqrt(-d) / 2.0 / a) <& ")");
                writeln("x2 = (" <& (-b / 2.0 / a) <& "," <& (-sqrt(-d) / 2.0 / a) <& ")");
            end if;
        end if;
    end if;
end func;

Комментарии

]]>

blog comments powered by Disqus

]]>

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