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

加入VIP,免费下载
 

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

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

下载须知

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

版权提示 | 免责声明

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

C语言编程习题.docx

1、C语言编程习题C语言编程习题第二章习题2-25. 用二分法编程求 6x4 -40x2+9=0 的所有实根。#include #include #define N 10000double A,B,C;double f(double x) return (A*x*x*x*x+B*x*x+C);void BM(double a,double b,double eps1,double eps2) int k; double x,xe; double valuea = f(a); double valueb = f(b); if (valuea 0 & valueb 0 | valuea 0 & val

2、ueb 0) return; printf(Finding root in the range: %.3lf, %.3lfn, a, b); for(k=1;k=N;k+) x=(a+b)/2; xe=(b-a)/2; if(fabs(xe)eps2 | fabs(f(x)eps1) printf(The x value is:%gn,x); printf(f(x)=%gnn,f(x); return; if(f(a)*f(x)0) b=x; else a=x; printf(No convergence!n);int main() double a,b,eps1,eps2,step,star

3、t; printf(Please input A,B,C:n); scanf(%lf %lf %lf,&A,&B,&C); printf(Please input a,b, step, eps1,eps2:n); scanf(%lf %lf %lf %lf %lf,&a,&b,&step,&eps1,&eps2); for (start=a; (start+step) = b; start += step) double left = start; double right = start + step; BM(left, right, eps1, eps2); return 0;运行:Ple

4、ase input A,B,C:6 -40 9Please input a,b, step, eps1,eps2:-10 10 1 1e-5 1e-5Finding root in the range: -3.000, -2.000The x value is:-2.53643f(x)=-0.00124902Finding root in the range: -1.000, 0.000The x value is:-0.482857f(x)=0.00012967Finding root in the range: 0.000, 1.000The x value is:0.482857f(x)

5、=0.00012967Finding root in the range: 2.000, 3.000The x value is:2.53643f(x)=-0.00124902有时若把判别语句if(fabs(xe)eps2 | fabs(f(x)eps1)改为if(fabs(xe)eps2 & fabs(f(x)eps1)会提高精度,对同一题运行结果:Finding root in the range: -3.000, -2.000The x value is:-2.53644f(x)=-4.26496e-007Finding root in the range: -1.000, 0.000T

6、he x value is:-0.482861f(x)=-7.3797e-006Finding root in the range: 0.000, 1.000The x value is:0.482861f(x)=-7.3797e-006Finding root in the range: 2.000, 3.000The x value is:2.53644f(x)=-4.26496e-007习题2-35. 请用埃特金方法编程求出x=tgx在4.5(弧度)附近的根。#include #include #define N 100#define PI 3.1415926void SM(double

7、 x0,double eps) int k; double x; double x1,x2; for(k=1;k=N;k+) x1=sin(x0)/cos(x0); x2=sin(x1)/cos(x1); x=x0-(x1-x0)*(x1-x0)/(x2-2*x1+x0); if(fabs(x-x0)eps) printf(The x value is:%gn,x); return; x0=x; printf(No convegence!n);int main() double eps,x0; printf(Please input eps,x0:n); scanf(%lf %lf,&eps,

8、&x0); SM(x0,eps); return 0;运行:Please input eps,x0:1e-5 4.5The x value is:4.49341习题2-411请编出用牛顿法求复根的程序,并求出 P(z)=z4-3z3+20z2+44z+54=0 接近于z0=2.5+4.5i 的零点。#include #include #define MAX_TIMES 1000typedef struct double real, image; COMPLEX;COMPLEX Aa5=54,0,44,0,20,0,-3,0,1,0;COMPLEX Bb4=44,0,40,0,-9,0,4,0;

9、COMPLEX zero = 0, 0;double eps1=1e-6;double eps2=1e-6;COMPLEX multi(COMPLEX a,COMPLEX b) COMPLEX result; result.real = a.real * b.real - a.image * b.image; result.image = a.image * b.real + a.real * b.image; return result;COMPLEX Div(COMPLEX a,COMPLEX b) COMPLEX z3; double s; s=(b.real*b.real)+(b.im

10、age*b.image); z3.real=b.real; z3.image=-b.image; z3=multi(a,z3); z3.real=z3.real/s; z3.image=z3.image/s; return z3;COMPLEX add(COMPLEX a,COMPLEX b) COMPLEX result; result.real = a.real + b.real; result.image = a.image + b.image; return result;COMPLEX subtract(COMPLEX a, COMPLEX b) COMPLEX result; re

11、sult.real = a.real - b.real; result.image = a.image - b.image; return result;COMPLEX times(COMPLEX z,int n) int i; COMPLEX result=1, 0; for (i=0;in;i+) result=multi(result,z); return result;double distance(COMPLEX a, COMPLEX b) return sqrt(a.real - b.real) * (a.real - b.real) + (a.image - b.image) *

12、 (a.image - b.image);double complex_abs(COMPLEX a) return sqrt(a.real * a.real + a.image * a.image);COMPLEX f(COMPLEX x) int i; COMPLEX result=zero; for (i=0;i5;i+) result=add(result,multi(Aai,times(x,i); return result;COMPLEX ff(COMPLEX x) int i; COMPLEX result=zero; for (i=0;i4;i+) result=add(resu

13、lt,multi(Bbi,times(x,i); return result;int main() COMPLEX z0,z1,result; double x,y; int k; printf(please input x,yn); scanf(%lf %lf,&x,&y); z0.real=x; z0.image=y; for(k=0; kMAX_TIMES; k+) z1 = subtract(z0, Div(f(z0), ff(z0); result = f(z1); if (distance(z0,z1)eps1 | complex_abs(result)eps2) printf(T

14、he root is: z=(%.3f + %.3fi), f(z)=(%e + %ei)n, z1.real,z1.image, result.real, result.image); return 0; z0 = z1; printf(No convergence!n); return 0;运行:please input x,y2.5 4.5The root is: z=(2.471 + 4.641i), f(z)=(-1.122705e-007 + -1.910245e-007i)习题2-62. 请编程用劈因子法求高次方程 x4+ x 3+5 x 2+4 x +4=0的所有复根。#inc

15、lude#includeint main() float b20,c20; float delta; float eps; int print=0; float fru0,fru1,s0,s1,frv0,frv1; float deltau,deltav; float u,v; float a20; int n,j; float r0,r1; float r; int i, k; printf(Please input max exponent:n); scanf(%d,&n); printf(Please input epslion:n); scanf(%f,&eps); printf(Pl

16、ease input the coefficient:n); for(i=0;i=n;i+) scanf(%f,&ai); for(j=0;j=n;j+) printf(+%.3fX%d,aj,n-j); printf(n); for(k=1;k=2;k+) u=an-1/an-2; v=an/an-2; if(k=2) u=0;v=4; while(1) b0=a0; b1=a1-u*b0; for(j=2;j=n;j+) bj=aj-u*bj-1-v*bj-2; r0=bn-1; r1=bn+u*bn-1; c0=b0; c1=b1-u*b0; for(j=2;j=n-2;j+) cj=b

17、j-u*cj-1-v*cj-2; s0=cn-3; s1=cn-2+u*cn-3; fru0=u*s0-s1; fru1=v*s0; frv0=-s0; frv1=-s1; deltau=-(frv1*r0-frv0*r1)/(fru0*frv1-fru1*frv0); deltav=-(fru1*r0-fru0*r1)/(frv0*fru1-frv1*fru0); u=u+deltau; v+=deltav; delta=u*u-4*v; if(fabs(deltau)eps)&(fabs(deltav)eps) print=1; printf(found roots:); r=-u/2;

18、i=(int) sqrt(fabs(delta)/2; if(delta0) printf(%.3f+%.3fit,r,fabs(double)i); printf(%.3f-%.3fin,r,fabs(double)i); else printf(%.3ftt,r+i); printf(%.3fn,r-i); if(n=1) printf(Found root :%.3fn,a1/a0); if(k=2) return 0; if(k=1&print) break; /* end while */ /* end for */ return 0;运行:Please input max expo

19、nent:4Please input epslion:1e-5Please input the coefficient:1 1 5 4 4+1.000X4+1.000X3+5.000X2+4.000X1+4.000X0found roots:-0.500+0.000i -0.500-0.000ifound roots:0.000+2.000i 0.000-2.000i习题3-15. 请编程用列全主元高斯约当消去法求矩阵A, B的逆矩阵。 #include #include #define MAX 10int ROW;static float AMAX+12*MAX+1;void putout(

20、) int i,j; printf(nThe reverse matrix is:n); for(i=1;i=ROW;i+) for(j=ROW+1;j=2*ROW;j+) printf(%.3f ,Aij); printf(n); int get() float maxMAX+1; int count_rMAX+1; float tmp2*MAX+1; float pass1,pass2; int i,j,k; for(i=1;i=ROW;i+) maxi=Aii; count_ri=i; for(k=i;k=ROW;k+) if(maxiAki) maxi=Aki; count_ri=k;

21、 /* find the max one*/ if(maxi=0) return -1; if(count_ri!=i) for(k=1;k=2*ROW;k+) tmpk=Acount_rik; Acount_rik=Aik; Aik=tmpk; /*change the rows*/ pass1=Aii; for(k=1;k=2*ROW;k+) Aik/=pass1; for(j=1;j=ROW;j+) if(j=i) continue; else pass2=Aji; for(k=1;k=MAX) printf(the number of row is too big!n); return

22、 0; printf(Please input the matrix A:n); for(i=1;i=ROW;i+) for(j=1;j=ROW;j+) scanf(%f,&p); Aij=p; if(tmpfabs(Aij) tmp=fabs(Aij); if(tmp=0) printf(No inverse!); return 0; for(i=1;i=ROW;i+) Aii+ROW=1; return get();运行:please input the number of ROW:3Please input the matrix A:-3 8 52 -7 41 9 -6The rever

23、se matrix is:0.026 0.396 0.285 0.068 0.055 0.094 0.106 0.149 0.021please input the number of ROW:4Please input the matrix A:2 1 -3 -13 1 0 7-1 2 4 -21 0 -1 5The reverse matrix is:-0.047 0.588 -0.271 -0.9410.388 -0.353 0.482 0.765-0.224 0.294 -0.035 -0.471-0.035 -0.059 0.047 0.294习题3-24. 编程用追赶法解下列三对角

24、线方程组。#include #include #define ROW 5static float AROW+1=0,0,0,0,0,0;static float BROW+1=0,0,0,0,0,0;static float CROW+1=0,0,0,0,0,0;static float XROW+1=0,0,0,0,0,0;int main() int i; printf(Please input the A:n); for(i=2;i=ROW;i+) scanf(%f,&Ai); printf(Please input the B:n); for(i=1;i=ROW;i+) scanf(%

25、f,&Bi); printf(Please input the C:n); for(i=1;i=ROW-1;i+) scanf(%f,&Ci); printf(Please input the F:n); for(i=1;i=ROW;i+) scanf(%f,&Xi); C1=C1/B1; for(i=2;i=ROW-1;i+) Ci=Ci/(Bi-Ai*Ci-1); X1=X1/B1; for (i=2; i=1;i-) Xi=Xi-Ci*Xi+1; printf (The value is : n); for(i=1;i=ROW;i+) printf (x%d=%.3fn,i,Xi); return 0;运行:Please input the A:-1 -1 -1 -1Please input the B:4 4 4 4 4 Please input the C:-1 -1 -1 -1Please input the F:100 200 200 200 100The value is : x1=46.154x2=84.615x3=92.308x4=84.615x5=46.154习题4-31. 用高斯赛

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

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