C语言编程:求方程ax^2+bx+c=0的实数根.a,b,c由键盘输入,a≠0且b^2-4ac>0.

提示:三角形面积公式为:area=sqrt(s*(s-a)*(s-b)*(s-c)),其中 s=(a+b+c)/2,求平方根函数是sqrt(),使用sqrt()函数需使用预编译命令#include"math.h"

#includ<stdio.h> main() { int a,b,c; float m,n,k,l,p,q; char s; s='i'; printf("input a b c:/n"); scanf("%d %d %d",&a,&b,&c); if(a==0) { m=-c/b; printf("the result is:%f",m); } if(a!=0) { k=b*b-4*a*c; if(k>0) { m=(-b-sqrt(k))/(2*a); //sqrt:开跟号; m,n既为两实根 n=(-b+sqrt(k))/(2*a); printf("the result is:m=%f n=%f",m,n); } if(k==0) { m=n=(-b)/(2*a); //两相等实根 printf("the result is:m=n=%f\n",m); } if(k<0) { l=4*a*c-b*b; p=-b/(2*a);q=sqrt(l)/(2*a); printf("the result is:m=%f+%f*%c\n",p,q,s); printf("n=%f-%f*%c\n",p,q,s); //求出两虚根 } } getch(); } 大体上对 你在遍译一下 我这机器上没tc追问

-b/(2*a)是怎么得出来的, 数学比较差,麻烦了

温馨提示:答案为网友推荐,仅供参考
相似回答