c语言ax bx c 0流程图,3.求解方程ax+bx+c=0的根,要求 (1)画出N-S流程图 (2)写出伪代码 (3)写出相应程序...

共回答了21个问题采纳率:85.7%

应该是Axx+Bx+C=0的根吧,我这写了个C语言的代码,至于第一步和第二步你还是看着代码自己完成吧,总不能完全依赖别人是吧...

// Solve Equation.cpp :Defines the entry point for the console application.

//

#include

#include

double a,b,c;

void initialize();//初始化工作

void Process();//求解过程

int main(int *argc,int *argv[])

{

int i;

char choice;

do{

i=0;

initialize();

Process();

printf("t go on?(y/n)n");

getchar();

scanf("%c",&choice);

if((choice=='y')||(choice=='Y'))

i=1;

}while(i);

return 0;

}

void initialize()

{

printf("-------------axx+bx+c=0----------------n");

printf("please input the factors:n");

printf("a=");

scanf("%lf",&a);

printf("b=");

scanf("%lf",&b);

printf("c=");

scanf("%lf",&c);

}

void Process()

{

double dt;//判别式

double x1,x2;

x1=x2=0;

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

if(0==a)

{

if(0==b)

printf("error:'a' and 'b' can`t be both zero!");

else if(0!=c)

printf("tX=%lfn-------the quation has only one rootn",-b/c);

else

printf("tX=0n-------the quation has only one rootn");

}

else

{

if(dt>=0)

{

dt=sqrt(dt);

x1=(-b+dt)/(2*a);

x2=(b+dt)/(2*a);

printf("tX1=%lf",x1);

printf("ntX2=%lf",x2);

printf("n-------the quation has two real root.");

}

else

{

dt=sqrt(-dt);

dt=dt/(2*a);

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

x2=b/(2*a);

printf("tX1=%lf+j%lf",x1,dt);

printf("ntX2=%lf-j%lf",x2,dt);

printf("n-------the quation has two imaginary rootn");

}

}

}

1年前

4

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值