C实现解一元二次方程
#include <stdio.h> #include <math.h> int main(void) { int a = 3; int b = 10; int c = 100; double data; double x1;//存放一个解 double x2;//存放第二个 data = c*c - 4*a*b; if(data>0) { x1 = (-b+sqrt(data))/(2*a); x2 = (-b-sqrt(data))/(2*a); printf("该一元二次方程有两个解\nx1 = %.2f\nx2 = %.2f\n",x1,x2);//打印两位小数 } else if(data==0) { x1 = (-b) / (2*a); x2 = x1; printf("该一元二次方程有唯一解\nx1=x2= %.2f\n",x1);//打印两位小数 } else printf("无解\n"); return 0; }