#include <stdio.h>
#include <math.h>
int main (void)
{
int a =1; //变量赋值
int b =2;
int c =1;
double delta;
double x1;
double x2;
delta = b*b - 4*a*c;
if (delta > 0)
{
x1 = (-b + sqrt(delta)) / (2*a);
x2 = (-b - sqrt(delta)) / (2*a);
printf("一元二次方程解:");
printf("x1 = %f,x2 = %f\n",x1,x2); //两个解
}
else if (delta == 0)
{
x1 = (-b)/(2*a);
x2 = x1;
printf("一元二次方程解:x1= %f\n",x1); //唯一解
}
else
{
printf("无解\n");
}
return 0;
}
#include <math.h>
int main (void)
{
int a =1; //变量赋值
int b =2;
int c =1;
double delta;
double x1;
double x2;
delta = b*b - 4*a*c;
if (delta > 0)
{
x1 = (-b + sqrt(delta)) / (2*a);
x2 = (-b - sqrt(delta)) / (2*a);
printf("一元二次方程解:");
printf("x1 = %f,x2 = %f\n",x1,x2); //两个解
}
else if (delta == 0)
{
x1 = (-b)/(2*a);
x2 = x1;
printf("一元二次方程解:x1= %f\n",x1); //唯一解
}
else
{
printf("无解\n");
}
return 0;
}