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语言训练-自由落体问题 (C语言代码)浏览:1733 |
【数组的距离】 (C语言代码)浏览:728 |
C语言程序设计教程(第三版)课后习题11.1 (C语言代码)浏览:676 |
printf基础练习2 (C语言代码)浏览:941 |
WU-蓝桥杯算法提高VIP-交换Easy (C++代码)浏览:1107 |
printf基础练习2 (C语言代码)浏览:746 |
A+B for Input-Output Practice (VI) (C语言代码)浏览:552 |
C二级辅导-公约公倍 (C语言代码)浏览:481 |
2006年春浙江省计算机等级考试二级C 编程题(1) (C语言代码)浏览:661 |
字符串比较 (C语言代码)浏览:680 |