如何在C中加入数学方程

red*_*ono 1 c math equation

我一直试图在Google上查看如何在我的程序中输入一个等式,但却无法找到任何方程式.你如何包括:

x = ( -b + ?b2 - 4ac ) / 2a  
Run Code Online (Sandbox Code Playgroud)

在该计划?

这是我的代码:

{
    int a, b, c;
    float x;

    //statements
    printf("Enter three integers: ");
    scanf("%d %d %d", &a, &b, &c);

    //computeforX

    x = ( -b + ?b2 - 4ac ) / 2a  

    printf("The value of x is %.1f", x);

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

Oli*_*rth 7

假设我们在这里谈论C(或C++),你将需要调查sqrt函数,也可能也需要调查函数pow(虽然这是不必要的,因为b-squared可以计算为b*b).

请注意,您需要将所有输入值转换为开始计算之前floatdouble之后,否则您将无法获得预期结果.