import java.util.Scanner;
import java.text.DecimalFormat;
public class Main {
static DecimalFormat df = new DecimalFormat("0.000");
public static void panduan(float a,float b,float c){
if(b*b-4*a*c<0)
xu(a,b,c);
else if(b*b-4*a*c==0)
weiyi(a,b,c);
else
shi(a,b,c);
}
public static void xu(float a,float b,float c){
float x = -b/(2*a);
float x1 = (float) (Math.sqrt(-b*b+4*a*c))/(2*a);
float x2 = (float) (Math.sqrt(-b*b+4*a*c))/(2*a);
System.out.print("x1="+df.format(x)+"+"+df.format(x1) +"i"+" "+"x2="+df.format(x)+"-"+df.format(x2)+"i");
}
public static void weiyi(float a,float b,float c){
float x = -b/(2*a);
System.out.print("x="+df.format(x));
}
public static void shi(float a,float b,float c){
float x1 = (float) ((-b+Math.sqrt(b*b-4*a*c))/(2*a));
float x2 = (float) ((-b-Math.sqrt(b*b-4*a*c))/(2*a));
System.out.print("x1="+df.format(x1)+" x2="+df.format(x2));
}
public static void main(String[] arg){
float a,b,c;
Scanner sc = new Scanner(System.in);
a = sc.nextInt();
b = sc.nextInt();
c = sc.nextInt();
panduan(a, b, c);
}
}
0.0分
2 人评分
C语言程序设计教程(第三版)课后习题5.4 (C语言代码)浏览:1911 |
C语言训练-自由落体问题 (C语言代码)浏览:1772 |
简单的a+b (C语言代码)浏览:717 |
C语言程序设计教程(第三版)课后习题10.1 (Java代码)浏览:1490 |
分糖果 (C++代码)浏览:1533 |
C语言程序设计教程(第三版)课后习题5.4 (C语言代码)浏览:937 |
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:668 |
简单的a+b (C语言代码)浏览:562 |
简单的a+b (C语言代码)浏览:673 |
C语言程序设计教程(第三版)课后习题6.8 (C++代码)浏览:613 |