Problem A: C語言實驗——一元二次方程Ⅱ
Time Limit: 1 Sec Memory Limit: 64 MB
Description
Input
Output
Sample Input
1 2 3
Sample Output
-1.00+1.41i -1.00-1.41i
HINT
參考答案:
#include<stdio.h>
#include<math.h>
int main()
{
int a,b,c;
double s;
double x1,x2,tem;
double m,n;
scanf("%d%d%d",&a,&b,&c);
s=b*b-4*a*c;
if(s>=0)
{
x1=(-b+sqrt(s))/(2*a);
x2=(-b-sqrt(s))/(2*a);
if(x1<x2)
{
tem=x1;
x2=x1;
x1=tem;
}
printf("%.2f %.2f",x1,x2);
}
else
{
m=-b/(2*a);
n=sqrt(-s)/(2*a);
printf("%.2f+%.2fi %.2f-%.2fi",m,n,m,n);
}
return 0;
}
編程軟件及學習視頻下載:點擊打開鏈接