]]> ]]>

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

Пример для версий Pike 7.6, Pike 7.8
int 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));
    }
    return 0;
}

Комментарии

]]>

blog comments powered by Disqus

]]>

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