#26551: 請問有哪裡可以改嗎?(嘆氣>m<


nihscs11023745 (unknown)


#include <iostream>

#include <math.h>

using namespace std;

 

int main(){

int c,z;

float a,b;

while (cin>>a>>b>>c)

{

z=pow(b,2)-4*a*c;

if(z>0)

cout

<<"Two different roots x1="<<(-b+sqrt(pow(b,2)-4*a*c))/2*a

<<" , x2="

<<(-b-sqrt(pow(b,2)-4*a*c))/2*a

<<endl;

if(z==0)

cout<<"Two same roots x="<<-b/2*a<<endl;

if(z<0)

cout<<"No real root"<<endl;

}

return 0;

}

#26577: Re:請問有哪裡可以改嗎?(嘆氣>m<


cges30901 (cges30901)


#include

#include

using namespace std;

 

int main(){

int c,z;

float a,b;

while (cin>>a>>b>>c)

{

z=pow(b,2)-4*a*c;

if(z>0)

cout

<<"Two different roots x1="<<(-b+sqrt(pow(b,2)-4*a*c))/2*a

<<" , x2="

<<(-b-sqrt(pow(b,2)-4*a*c))/2*a

<<endl;

if(z==0)

cout<<"Two same roots x="<<-b/2*a<<endl;

if(z<0)

cout<<"No real root"<<endl;

}

return 0;

}

2*a要用括號包起來

這個月已經有四個人沒用括號上來發問了...(嘆氣>m<