作者jiby (謝謝)
看板CSSE
標題求解一元二次方程式
時間Sat Apr 30 13:57:09 2005
哪錯了
compile不出來
各位大大指教我吧
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
float judge(float,float,float);//判斷式函數
int main(void)
{
float a,b,c;//declare a int variable
printf("input the three varibles a,b,c");
scanf("%d,%d,%d",&a,&b,&c);
judge(a,b,c);
float d;//jugement variable
d=judge(a,b,c);//indicate the of jugement equation to d variable
if(d>0)
{
float r1,r2;
r1=(-b+d)/(2*a),r2=(-b-d)/(2*a);
printf("the answe is %f,%f,\n",r1,r2);
}
else if(d=0)
{
float rr;//root reapted!
rr=-b/(2*a);
printf("the answer is double roots %f",rr);
}
else
{
float r,c1,c2;//r represents a real part,c1 and c2 is complex part
r=-b/2*a;
c1=d;
c2=-d;
printf("the answe is %f+i%f and %f+i%f,r,c1,r,c2");
}
return 0;
}
float judge(float a,float b,float c)
{
float d,e;
d=b*b-4*a
e=sqrt(d);
return e;
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 59.114.150.35
1F:推 edwar:判別式b^2-4*a*c; 不用急著求平方根, 負的會 error 211.76.58.8 05/01
2F:推 jojochuang:起碼排個版吧...真沒誠意 140.113.141.98 05/02
3F:推 Leland:這個程式真是令人看不下去,錯誤太多了 @@ 140.112.30.50 05/03