3.求解方程ax+bx+c=0的根,要求 (1)画出N-S流程图 (2)写出伪代码 (3)写出相应程序
来源:学生作业帮 编辑:神马作文网作业帮 分类:综合作业 时间:2024/09/21 03:27:53
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");
}
}
}
// 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");
}
}
}
3.求解方程ax+bx+c=0的根,要求 (1)画出N-S流程图 (2)写出伪代码 (3)写出相应程序
用C语言 求解方程ax*x+bx+c=0的根,要求:画出N—S流程图,写出伪代码,并写出相应程序
编写程序计算s=1+3+5+...+n求s=100得值,请画出流程图,并写出相应的VB语句代码
计算写出伪代码,画出流程图.
试用伪代码写出a1a2到a100中最小数的一个算法并画出流程图
输入abc三个数算出三个数最大的一个数,写出伪代码,画出流程图
编写伪代码,求1+1/(1*2)+1/(1*2*3)+1/(1*2*3*4).+1/(n!)画出流程图
vb程序改错 求解一元二次方程(ax^2+bx+c=0)的程序
设计一个计算简单算法设计一个计算S=1+3+5+.+49的流程图并写出相应程序
写出计算S=1+(1+2)+(1+2+3)+...+(1+2+...+50)的算法并画出相应的程序框图
写出求一元二次方程ax²+bx+c=0的解的流程图
求S=1-1/2+1/3-1/4+...-1/n的值(n为偶数,由键盘输入),要求有流程图,代码