mnbn.net
当前位置:首页 >> 一元二次方程程序 >>

一元二次方程程序

#include #include int main(void) { double a,b,c,x1,x2,d; scanf("%lf%lf%lf",&a,&b,&c); d = b * b - 4 * a * c; if(d > 0) { x1 = (-1 * b + sqrt(d)) / (2 * a); x2 = (-1 * b - sqrt(d)) / (2 * a); printf("x1 = %g,x2 = %g\n",x1,x2); }...

步骤: 打开visual C++ 6.0-文件-新建-文件-C++ Source File 2. 定义变量: #include #include void main() { double a,b,c; /*定义系数变量*/ double x1,x2,p; /*定义根变量和表达式的变量值*/ 3.输入系数: printf("请输入a,b,c:"); /*提示用...

double x1 = 0;//解1double x2 = 0;//解2Console.WriteLine("求 ax^2+bx+c=0 的解");Console.Write("请输入a的值:");double a = Convert.ToInt32(Console.ReadLine());Console.Write("请输入b的值:");double b = Convert.ToInt32(Console.Read...

C语言编写一程序求解一元二次方程的根: #include #include void m(float a,float b,float c) { double x1,x2; x1=(-b+sqrt(b*b-4*a*c))/(2*a); x2=(-b-sqrt(b*b-4*a*c))/(2*a); printf("方程的根是%.2lf和%.2lf",x1,x2); } void n(float a,floa...

#include#includevoid main(){ double a,b,c,d,x1,x2; /*sqrt要求用double型,定义用double,另外double和后面变量之间要有空格*/ printf("请输入系数a、b、c:"); scanf("%lf%lf%lf",&a,&b,&c); /*&b和&c之间要有逗号*/ d=b*b-4*a*c; x1=(-b+sqr...

#include #include #include void main() { float a,b,c; float result1; float result2; printf("input a,b,c"); scanf("%f,%f,%f", &a, &b, &c); if (sqr(b)-4*a*c > 0) { result1 = (-1 * b + sqrt(sqr(b)-4*a*c))/(2*a); result2 = (-1 * b ...

#include #include void main( void ) { double a,b,c,d; printf("请输入一元二次方程的三个系数:"); scanf("%lf %lf %lf",&a,&b,&c); d=b*b-4*a*c; if(d

给个算法的框架,你可以自己细化。 #include "math.h" float a, b, c, delta; scanf("%f,%f,%f", &a, &b, &c); delta=b*b-4*a*c; if(delta==0) { printf("Result is %5.2f\n", -b/(2*a)); } else if(delta >0) { printf("Result is %5.2f, %5.2f...

public static main(String[] arg0){ if(arg0== null || arg0.length == 0){ System.out.println("请输入参数:a,b,c"); System.exit(0); } for(int i=0;i= 2){ b = Float.parseFloat(arg0[1]); } if(arg0.length >= 3){ c = Float.parseFloat...

#include #include void main() {float a,b,c,disc,x1,x2,realpart,imagpart; scanf("%f,%f,%f",&a,&b,&c);/*输入abc值*/ disc=b*b-4*a*c;/*判断△是不是大小*/ if(fabs(disc)0.0001) {x1=(-b+sqrt(disc))/(2*a); x2=(-b-sqrt(disc))/(2*a); prin...

网站首页 | 网站地图
All rights reserved Powered by www.mnbn.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com