Квадратное уравнение в D
Пример для версий
GDC 0.24
import std.c.stdio;
import std.stdio;
import std.math;
int main() {
int A, B, C;
writef("A = ");
scanf("%d", & A);
if (A==0)
{ writefln("Not a quadratic equation.");
return 0;
}
writef("B = ");
scanf("%d", & B);
writef("C = ");
scanf("%d", & C);
A*=2;
float D = B*B-2*A*C;
if (D == 0)
{ writefln("x = %f\n",-B*1.0/A);
return 0;
}
if (D>0)
writefln("x1 = %f\nx2 = %f",(-B+sqrt(D))/A,(-B-sqrt(D))/A);
else
writefln("x1 = (%f, %f)\nx2 = (%f, %f)",-B*1.0/A,sqrt(-D)/A,-B*1.0/A,-sqrt(-D)/A);
return 0;
}
Комментарии
]]>blog comments powered by Disqus
]]>