#11360: c++ answer


TzuchunChen (陳子濬)

學校 : 國立嘉義高級中學
編號 : 59216
來源 : [49.215.236.123]
最後登入時間 :
2019-05-06 08:46:33
a006. 一元二次方程式 | From: [27.105.47.171] | 發表日期 : 2016-09-14 21:11

#include <iostream>
#include <math.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

using namespace std;

int main(int argc, char** argv) {
 
 int a, b, c, d;
 
 while(cin >> a >> b >> c)
 {
  d=b*b-4*a*c;
  
  if(d>0){cout <<"Two"<<" "<<"different"<<" "<<"roots"<<" "<<"x1="<<(-b+pow(d,0.5))/(2*a)<<" "<<","<<" "<<"x2="<<(-b-pow(d,0.5))/2<<endl;}
  
  else if(d==0){cout<<"Two"<<" "<<"same"<<" "<<"roots"<<" "<<"x="<<(-b)/(2*a)<<endl;}
  
  else if(d<0){cout<<"No"<<" "<<"real"<<" "<<"root"<<endl;}
 }
 
 return 0;
}

 
ZeroJudge Forum