求简单源代码
求解ax2+bx+c=0
谢~
随便写一个啦
#include <math.h> #include <stdlib.h> #include <stdio.h>
void main(void) { double a, b, c, root1, root2, delta; a = 1; b = -2; c = 6; delta = b*b - 4*a*c; if(delta < 0) { printf("Warming! delta < 0,There is no root!\n"); exit(0); } else if(delta == 0) { root1 = -(0.5*b/a); printf("There are two equal roots:root1 = root2 = %f\n", root1); } else { root1 = -b + sqrt(delta); root2 = -b - sqrt(delta); root1 = 0.5*root1 / a; root2 = 0.5*root2 / a; printf("There are two equal roots:root1 = %f;root2 = %f\n", root1, root2); } }