#include<cstdio>
#include<cmath>
int main()
{
int n,a,b,c,root1,root2,j;
while((scanf("%d%d%d",&a,&b,&c))!=EOF)
{
if((b*b-4*a*c)<0)
printf("No real root\n");
else if((b*b-4*a*c)==0)
{
root1=(-b-sqrt(b*b-4*a*c))/2*a;
printf("Two same roots x=%d\n",root1);
}
else if((b*b-4*a*c)>0)
{
root1=(-b+sqrt(b*b-4*a*c))/2*a;
root2=(-b-sqrt(b*b-4*a*c))/2*a;
if(root1>root2)
printf("Two different roots x1=%d , x2=%d\n",root1,root2);
else
printf("Two different roots x1=%d , x2=%d\n",root2,root1);
}
}
return 0;
}
#include
#include
int main()
{
int n,a,b,c,root1,root2,j;
while((scanf("%d%d%d",&a,&b,&c))!=EOF)
{
if((b*b-4*a*c)<0)
printf("No real root\n");
else if((b*b-4*a*c)==0)
{
root1=(-b-sqrt(b*b-4*a*c))/2*a;
printf("Two same roots x=%d\n",root1);
}
else if((b*b-4*a*c)>0)
{
root1=(-b+sqrt(b*b-4*a*c))/2*a;
root2=(-b-sqrt(b*b-4*a*c))/2*a;
if(root1>root2)
printf("Two different roots x1=%d , x2=%d\n",root1,root2);
else
printf("Two different roots x1=%d , x2=%d\n",root2,root1);
}
}
return 0;
}
2*a要括弧 變成 (2*a)
否則算是會變為 先/2再*a
#include
#include
int main()
{
int n,a,b,c,root1,root2,j;
while((scanf("%d%d%d",&a,&b,&c))!=EOF)
{
if((b*b-4*a*c)<0)
printf("No real root\n");
else if((b*b-4*a*c)==0)
{
root1=(-b-sqrt(b*b-4*a*c))/2*a;
printf("Two same roots x=%d\n",root1);
}
else if((b*b-4*a*c)>0)
{
root1=(-b+sqrt(b*b-4*a*c))/2*a;
root2=(-b-sqrt(b*b-4*a*c))/2*a;
if(root1>root2)
printf("Two different roots x1=%d , x2=%d\n",root1,root2);
else
printf("Two different roots x1=%d , x2=%d\n",root2,root1);
}
}
return 0;
}
2*a要括弧 變成 (2*a)
否則算是會變為 先/2再*a
真是非常感謝!!卡在這個點有點困擾^_^