我已经按照对二次方程转换为整数
#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它们是二次方程中的变量。 –