我已經按照對二次方程轉換爲整數
#include <iostream>
#include <math.h>
using namespace std;
int main(){
float x,x1;
x=0;x1=0;
int a=1;
int b;
int c;
cout<<"enter the second term:"<<endl;
cin>>b;
cout<<"enter the third term:";
cin>>c;
float d=b^2-4*a*c;
if (d<0){
cout<<"the equation has not real solution :"<<endl;
}
else if (d==0) { x=(-b/2); x1=x;}
else
{
x=(-b+sqrt(d))/2;x1=(-b-sqrt(d))/2;
}
cout<<"roots are :"<<x<< " "<<x1<< " "<<endl;
return 0;
}
的計算根simpled算法,但它給我警告
arning C4244: '=' : conversion from 'int' to 'float', possible loss of data
,當我進入-6和9它給出了根是6和零當然是不正確的請幫助我
處理你的變量名!什麼是X? X1?一個? B' C? d?哦。我的。神。此外,正確的縮進。那裏有什麼空行? –
@Konrad Rudolph,我會說在這種情況下,它是可以的,因爲它顯然是按照慣例使用這些字母的二次公式 –
@Konrad它們是二次方程中的變量。 –