#include <stdio.h>
#include <math.h>
int main (void)
{
int a = 1; //声明变量 赋值
int b = 5;
int c = 6;
float delta;
float x1;
float x2;
delta = b*b - 4*a*c; //赋值
if(delta > 0) //选择条件
{
x1 = (-b + sqrt(delta)) / (2*a);//运算式
x2 = (-b - sqrt(delta)) / (2*a);
printf("x1 = %f,x2 = %f\n",x1,x2);
}
else if (delta == 0)
{
x1 = (-b) / (2*a);
x2 = x1;
printf("x1 = x2 = %f",x1);
}
else(delta < 0)
{
printf("error\n");
}
return 0;
}
PS:在linux的GCC中,如以上程序保存为yyec.c,编译保存为y文件,
命令为 []#gcc -o y yyec.c -lm(LM为连接<math.h>文件)方能编译成功
转载于:https://blog.51cto.com/feqw4277/1212308