#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main(void)
{
int a,b,c;
double x1,x2;
while(scanf("%d %d %d",&a,&b,&c)!=EOF)
if(b*b-4*a*c>0){
printf("Two different roots x1=%.0lf , x2=%.0lf\n",(-1*b+sqrt(b*b-4*a*c))/2*a,(-1*b-sqrt(b*b-4*a*c))/2*a);}
else if((b*b-4*a*c)==0){
printf("Two same roots x=%.0lf\n",(-1*b-sqrt(b*b-4*a*c))/2*a);}
else if((b*b-4*a*c)<0){
printf("No real root\n");}
return 0;
}
只能80分==
#include
#include
#include
int main(void)
{
int a,b,c;
double x1,x2;
while(scanf("%d %d %d",&a,&b,&c)!=EOF)
if(b*b-4*a*c>0){
printf("Two different roots x1=%.0lf , x2=%.0lf\n",(-1*b+sqrt(b*b-4*a*c))/2*a,(-1*b-sqrt(b*b-4*a*c))/2*a);}
else if((b*b-4*a*c)==0){
printf("Two same roots x=%.0lf\n",(-1*b-sqrt(b*b-4*a*c))/2*a);}
else if((b*b-4*a*c)<0){
printf("No real root\n");}
return 0;
}
只能80分==
是不是最後一個無法通過?
我也一樣,求救= =
#include
#include
#include
int main(void)
{
int a,b,c;
double x1,x2;
while(scanf("%d %d %d",&a,&b,&c)!=EOF)
if(b*b-4*a*c>0){
printf("Two different roots x1=%.0lf , x2=%.0lf\n",(-1*b+sqrt(b*b-4*a*c))/2*a,(-1*b-sqrt(b*b-4*a*c))/2*a);}
else if((b*b-4*a*c)==0){
printf("Two same roots x=%.0lf\n",(-1*b-sqrt(b*b-4*a*c))/2*a);}
else if((b*b-4*a*c)<0){
printf("No real root\n");}
return 0;
}
只能80分==
我是寫C++的 我當初也因為最後一題錯 而煩惱
最後一個錯誤的是Two same roots x= 這一行
我原本判斷由(-b+sqrt(b*b-4*a*c))/2*a 改成 (-b+sqrt(b*b-4*a*c))/(2*a)
AC過關!!