3.求解方程ax+bx+c=0的根,要求 (1)画出N-S流程图 (2)写出伪代码 (3)写出相应程序
题目
3.求解方程ax+bx+c=0的根,要求 (1)画出N-S流程图 (2)写出伪代码 (3)写出相应程序
答案
应该是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=%lf\n-------the quation has only one root\n",-b/c);
else
printf("\tX=0\n-------the quation has only one root\n");
}
else
{
if(dt>=0)
{
dt=sqrt(dt);
x1=(-b+dt)/(2*a);
x2=(b+dt)/(2*a);
printf("\tX1=%lf",x1);
printf("\n\tX2=%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("\n\tX2=%lf-j%lf",x2,dt);
printf("\n-------the quation has two imaginary root\n");
}
}
}
举一反三
已知函数f(x)=x,g(x)=alnx,a∈R.若曲线y=f(x)与曲线y=g(x)相交,且在交点处有相同的切线,求a的值和该切线方程.
我想写一篇关于奥巴马的演讲的文章,写哪一篇好呢?为什么好
最新试题
热门考点
- 有甲、乙两导体,甲的横截面积是乙的两倍,而单位时间内通过导体横截面积的电荷量,乙是甲的两倍,下例说法正确的是( )
- 因式分解:1.(x2+2x)2-x2-2x-2 2.化简:1+x+x(1+x)+x(1+x)2+...+x(1+x)1998
- 急需杂诗十二首其二翻译
- she said,"I want to make another film."
- mary began to learn the english language 和mary began to learn english 都可以把?
- 有理数a、b、c在数轴上的位置如图所示: 若m=|a+b|-|b-1|-|a-c|-|1-c|,则1000m=_.
- 句子魔法(按要求改写句子).
- 一个铅球的质量是3kg,若让它长时间地暴露在潮湿的空气中,它的质量会不变、大于3kg还是小于3kg
- 1、人口增长取决于( )
- 用一根绳子测量一棵树树干的周长,将绳子3折围一圈多1米,将绳子4折围一圈少1米,问绳子和树干的周长?