正在加载图片...
The C Programming language Chapter 4 Input and Output 例求ax2+bx+c=0方程的根,设b2-4ac>0 /ch314.c*/ b± 4 #include <stdio h> 2a #include <math. h main( i float a, b, c, disc, x1, x2, p, q scanf(a=%f, b=%f,c=%f, &a, &b, &c) disc=b*b-4ac p=-b/(2a); q=sqrt(disc)(2*a) XIp p-q2 printf("nnx1=%5.2fnx2=%05.2fn", x1, 2); 输入:a=1.b=3.c=2 输出:X1=-1.00 2=2.00The C Programming Language Chapter 4 Input and Output /*ch3_14.c*/ #include <stdio.h> #include <math.h> main() { float a,b,c,disc,x1,x2,p,q; scanf("a=%f,b=%f,c=%f",&a,&b,&c); disc=b*b-4*a*c; p=-b/(2*a); q=sqrt(disc)/(2*a); x1=p+q; x2=p-q; printf("\n\nx1=%5.2f\nx2=%5.2f\n",x1,x2); } 输入:a=1,b=3,c=2  输出:x1=-1.00 x2=-2.00
<<向上翻页
©2008-现在 cucdc.com 高等教育资讯网 版权所有