java一元二次方程求根问题_对一元二次方程求解

#include

float sqrt(float x)

{

const float epsilon= 0.0001;

float guess=1.0;

if(x<0)

{

printf("Negative argument to squareRoot.\n");

return -1.0;

}

while (((guess*guess)-x)>=epsilon)

{

guess=(x/guess+guess)/2.0;

}

return guess;

}

void qiuJie(int a,int b,int c)

{

float result=float(b*b-4*a*c);

if(result<0)

{

printf("方程的根是复数!\n");

}

else

{

float x1=(-b+sqrt(result))/(2*a);

printf("The first answer is %.2f.\n",x1);

float x2=(-b-sqrt(result))/(2*a);

printf("The second answer is %.2f.\n",x2);

}

}

int main(void)

{

int num1,num2,num3;

printf("Enter three numbers !\n");

scanf("%i",&num1);

scanf("%i",&num2);

scanf("%i",&num3);

qiuJie(num1,num2,num3);

return 0;

}

运行图:

7c4786d14f942da18dd9fcf4fd0fc9fa.png

已标记关键词 清除标记
表情包
插入表情
评论将由博主筛选后显示,对所有人可见 | 还能输入1000个字符
相关推荐
©️2020 CSDN 皮肤主题: 游动-白 设计师:白松林 返回首页