ImageVerifierCode 换一换
格式:DOCX , 页数:16 ,大小:18.26KB ,
资源ID:12666134      下载积分:10 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/12666134.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(用C解决一元二次方程根的问题集锦.docx)为本站会员(b****3)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

用C解决一元二次方程根的问题集锦.docx

1、用C解决一元二次方程根的问题集锦c+求一元二次方程ax+bx+c=0的根一#include #include #define ESSP 0.00000001 void main() double a,b,c,delta,root1,root2; couta; coutb; coutc; delta=b*b-4*a*c; if(delta-ESSP) coutThis equation has no real root.ESSP) root1=(-b+sqrt(delta)/(2*a); root2=(-b-sqrt(delta)/(2*a); coutThis eqution has two

2、unequalize roots:root1root2endl; else root1=-b/(2*a); coutThis eqution has two equalize roots:root1endl; 二结构化编程方法: /for two roots #include #include int main() double a,b,c,rp,ip;/方程系数 double x1,x2;/方程的根 double d;/根的判别式 coutabc; if(a=0) cout= 0) if (d=0) x1 = -b / (2*a); cout只有一个实根:x1endl; else x1 =

3、( -b + sqrt ( d ) ) / ( 2 * a ); x2 = ( -b - sqrt ( d ) ) / ( 2 * a ); cout有二个实根:x1andx2endl; else rp = -d/(2*a); ip = sqrt ( -d ) /(2*a); x1 = rp + ip ; x2 = rp - ip ; cout有二个虚根:x1iandx2i0) x1=(-b+sqrt(d)/(2*a); x2=(-b-sqrt(d)/(a*a); else if(d=0) x1=x2=(-b)/(2*a); else double rp = -d/(2*a); double

4、ip = sqrt ( -d ) /(2*a); x1=rp + ip; x2=rp - ip; void FindRoot:Display() if(d0) coutx1=x1nx2=x2endl; else if(d=0) coutx1=x2=x1endl; else coutx1=x1iendl; coutx2=x2iendl; void main() FindRoot obj(1,2,3); obj.Find(); obj.Display(); 三根据要求编写程序。 从键盘输入三个实数a、b、c分别作为一个一元二次方程ax2+bx+c=0 的三个系数。使用系 统给出的平方根函数,编写一

5、段程序,使之求出这个方程的两个根。其中,求=b2-4*a*c 的功能要以函数形式出现。(提示:求根公式,0) x1=(-b)+sqrt(disc); x2=(-b)-sqrt(disc); printf(x1=%.2ftx2=%.2fn,x1,x2); else printf(b-4ac0,该方程没有实根n,x1,x2); #include stdio.h int a8=0; int getResult(int n) if(n=1|n=2) return 1; else return 3*getResult(n-1)-getResult(n-2); void main() int i; a0=

6、1; a1=1; for(i=2;i8;i+) ai=getResult(i+1); for(i=0;i8;i+) printf(a%d = %dn,i+1,ai); 四用C语言编写一个程序,计算一元二次方程的解(x1,x2)。一元二次方程:Ax2+Bx+C=0 (假设A=4,B=6,C=1)按顺序输入a,b,c #include stdio.h #include stdlib.h #include math.h int main() float a,b,c; scanf(%f,&a); scanf(%f,&b); scanf(%f,&c); printf(%fn,(-b+sqrt(b*b-4

7、*a*c)/2/a); printf(%f,(-b-sqrt(b*b-4*a*c)/2/a); system(pause); return 0; ;五解一元二次方程的C+程序 #include #include #include void sqrt1(double,double); void sqrt2(double,double); void printer(double,double); void main() float a,b,c; double x1,x2; cout请输入a,b,c:abc; if(b*b-4*a*c !=0) if(b*b-4*a*c) sqrt1(x1,x2);

8、 else printer(x1,x2); else sqrt2(x1,x2); void sqrt1(double x1,double x2) /b*b-4ac0 float a,b,c; if(a!=0) x1=(-b+sqrt(b*b-4*a*c)/(2*a); x2=(-b-sqrt(b*b-4*a*c)/(2*a); coutx1=x1setw(5)x2=x2endl; else if(b=0) if(c=0) coutx为任意解endl; else cout无解endl; else x1=x2=-c/b; coutx1=x2=x1endl; void sqrt2(double x1

9、,double x2) /b*b-4ac=0 float a,b,c; x1=x2=-b/(2*a); coutx1=x2=x1endl; void printer (double x1,double x2) /b*b-4ac0 float a,b,c; char i=i;/i后面为虚部 x1=(-b/(2*a)+(i*(sqrt(b*b-4*a*c)/(2*a); x2=(-b/(2*a)-(i*(sqrt(b*b-4*a*c)/(2*a); coutx1=x1tx2=x20,有两个不等实根。 (4) b2-4ac0,有两个复根(表示成x+yi,x-yi)。 2编写一个程序,打印下列图形:

10、1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 3. 编写一个函数将一nxn矩阵转置(即aij与aji的值交换),然后编写一main( ) 函数调用它(取n=3)。第1个我记得书上有例题的 第2个: #include int main() for(int i=1;i=5;i+) for(int j=1;j=i;j+) printf(%d,j); printf(n); return 0; 3. #include #define N 3 int main() void f(int); int aNN; for(int i=0;iN;i+) for(int j=0;jN;j+) scan

11、f(%d,&aij); f(a); for(int i=0;iN;i+) for(int j=0;jN;j+) printf(%d,aij); printf(n); return 0; void f(int a) int temp; for(int i=0;iN;i+) for(int j=i;jN;j+) temp=aij; aij=aji; aji=temp; 七(复数)#include iostream.h #include math.h void main() float a,b,c; couta; coutb; coutc; if(b*b-4*a*c0) coutNo radix i

12、n real number!endl; complex x1,x2; x1 = complex(-b)/(2*a), sqrt(-d)/(2*a); x2 = complex(-b)/(2*a), -(sqrt(-d)/(2*a); return; 八 建立复数类求方程的根#include #include #include using namespace std; int main(void) double a = 1.0, b = 0.0, c = 1.0; / ax2 + bx + c = 0 complex x1,x2; double d = b * b - 4.0 * a * c;

13、if (d = 0) x1 = (-b + sqrt(d)/(2*a); x2 = (-b - sqrt(d)/(2*a); else x1 = complex(-b)/(2*a), sqrt(-d)/(2*a); x2 = complex(-b)/(2*a), -(sqrt(-d)/(2*a); cout x1 = x1.real() + x1.imag() i endl; cout x2 = x2.real() + x2.imag() i endl; return 0; 九复数类如下: #include #include / class class complex private: dou

14、ble a,b; double _copy; public: double getreal(); double getimag(); double getZ(); void solution(double a,double b,double c,double p,complex &x1,complex &x2); complex(int x) a=x;b=0; complex(double av,double bv):a(av),b(bv) complex() complex(complex& _copy) a=_copy.a; b=_copy.b; friend ostream& opera

15、tor(istream& g,complex& i); friend complex operator+(complex& x,complex& y); friend complex operator-(complex& x,complex& y); friend complex operator*(complex& x,complex& y); friend complex operator/(complex& x,complex& y); complex operator=(complex& y); void output() coutz=sqrt(a*a)+(b*b)endl; void

16、 put() cout(a+bi)endl; void gen() int sign=1, double g,h; if(b0) sign=-1; else sign=1; g=sqrt(sqrt(a*a)+(b*b)+a)/2); h=sign*sqrt(sqrt(a*a)+(b*b)-a)/2); coutthe sqrt-root is: g+hiendl; ; ostream& operator(istream& stream,complex& x) coutx.a; coutx.b; return stream; /add complex operator+(complex& x,c

17、omplex& y) return complex(x.a+y.a,x.b+y.b); /sub complex operator-(complex& x,complex& y) return complex(x.a-y.a,x.b-y.b); /mul complex operator*(complex& x,complex &y) return complex(x.a*y.a)-(x.b*y.b),(x.a*y.b)+(x.b*y.a); /div complex operator/(complex& x,complex& y) return complex(x.a*y.a+x.b*y.b)/(y.a*y.a+y.b*y.b),(x.b*y.a-x.a*y.b)/(y.a*y.a+y.b*y.b); /assignment complex complex:operator=(complex& y) this-a=y.a; this-b=y.b; return *this; double complex:getreal() return a; double complex:getimag() return b; double complex:getZ(

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1