一元二次方程ax的平方c语言,一道C语言的作业,,大概意思是,求解答一个一元二次方程,AX平方? 爱问知识人...

楼主你好。

以下是我的代码:

#include

#include

int main(){

double a,b,c;

double x1,x2;

double deta;

while(1){

printf("Please enter a, b and c:");

scanf("%lf %lf %lf",&a, &b, &c);

printf("a=%。

2f, b=%。2f, c=%。2f

", a, b, c);

deta = b*b-4*a*c;

if(deta < 0){//若deta小于零,提示用户此方程无实数解

printf("deta is negtive! This quation doesn't have a real solution!

");

}else{

if(deta == 0){

x1=x2= -b/(2*a);

}else{

deta = sqrt(deta);

x1 = (-b deta)/(2*a);

x2 = (-b-deta)/(2*a);

}

printf("x1=%。

2f, x2 = %。2f

", x1, x2);

}

printf("==========================================

");

}

return 1;

}

输出:

Please enter a, b and c:1 -7 12

a=1。

00, b=-7。00, c=12。00

x1=4。00, x2 = 3。00

==========================================

Please enter a, b and c:2 -6 -20

a=2。

00, b=-6。00, c=-20。00

x1=5。00, x2 = -2。00

==========================================

Please enter a, b and c:1 4 3

a=1。

00, b=4。00, c=3。00

x1=-1。00, x2 = -3。00

==========================================

Please enter a, b and c:4 1 4

a=4。

00, b=1。00, c=4。

00

deta is negtive! This quation doesn't have a solution!

==========================================

Please enter a, b and c:。

全部

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值