zl程序教程

您现在的位置是:首页 >  工具

当前栏目

c源码编译

源码 编译
2023-09-11 14:14:58 时间

 

#include<stdio.h>
#include<math.h>               //程序中要调用求平方根函数sqrt

int main()
{
    double a,b,c,disc,x1,x2,p,q;
    scanf("%lf%lf%lf",&a,&b,&c);
    disc = b * b - 4 * a * c;
    p = -b / (2.0 * a);
    q = sqrt(disc) / (2.0 * a);
    x1 = p + q,x2 = p - q;
    printf("x1=%7.2f\nx2=%7.2f\n",x1,x2);
    return 0;
}

编译时需要注意,在 Linux 系统下,C 源文件若调用了 math 库里的函数,则编译时要加上 -lm (是字母 l ,不是数字1),表示链接到 math 库。

gcc -o 5-5 5-5.c -lm