Quadratic equation in Pike
Example for versions
Pike 7.8
void main()
{
int A = (int)Stdio.stdin->gets();
if (A == 0)
{
write("Not a quadratic equation.\n");
return 0;
}
int B = (int)Stdio.stdin->gets();
int C = (int)Stdio.stdin->gets();
int D = (B*B-4*A*C);
write(D+"\n");
if (D == 0)
write(sprintf("x = %f\n",-B/2.0/A));
else if (D > 0)
{
write(sprintf("x1 = %f\n", (-B+sqrt(D))/2.0/A));
write(sprintf("x2 = %f\n", (-B-sqrt(D))/2.0/A));
}
else
{
write(sprintf("x1 = (%f, %f)\n", -B/2.0/A, sqrt(-D)/2.0/A));
write(sprintf("x1 = (%f, %f)\n", -B/2.0/A, -sqrt(-D)/2.0/A));
}
}
Comments
]]>blog comments powered by Disqus
]]>