#28945: -1重根錯誤


NightWinds (夜風清冷)


#include<stdio.h>

#include<math.h>

main()

{

int a,b,c,x,x1,x2,t;

scanf("%d %d %d",&a,&b,&c);

t=(b*b)-(4*a*c);

if(t>0)

{

x1=(-b+sqrt(t))/2*a;

x2=(-b-sqrt(t))/2*a;

printf("Two different roots x1=%d , x2=%d",x1,x2);

}

else if(t==0)

{

x=(-b+sqrt(t))/2*a;

printf("Two same roots x=%d",x);

}

else

printf("No real root");

}

不知道問題在哪

還請各位幫忙

#28946: Re:-1重根錯誤


linlincaleb@gmail.com (臨末之頌)


#include

#include

main()

{

int a,b,c,x,x1,x2,t;

scanf("%d %d %d",&a,&b,&c);

t=(b*b)-(4*a*c);

if(t>0)

{

x1=(-b+sqrt(t))/2*a;

x2=(-b-sqrt(t))/2*a;

printf("Two different roots x1=%d , x2=%d",x1,x2);

}

else if(t==0)

{

x=(-b+sqrt(t))/2*a;

printf("Two same roots x=%d",x);

}

else

printf("No real root");

}

不知道問題在哪

還請各位幫忙

2*a 要括號 (-b+sqrt(t))/(2*a)