云题海 - 专业文章范例文档资料分享平台

当前位置:首页 > c语言上机实验题

c语言上机实验题

  • 62 次阅读
  • 3 次下载
  • 2025/5/4 2:28:27

}

25.用牛顿迭代法求方程3x3-3x2+x-1=0在x0=2附近的实根。要求: (1)用函数float newtoon(float x)求方程在x附近的根;

(2)用函数float F(float x)求x处的函数值,用函数float F1(float x)求f(x)在x处的导数; (3)在主函数中输入x0,调用函数求得方程的近似根(精度要求为10-5),并输出结果。 请完善下列程序,使之完成上述功能。并请以注释的方式在程序的最后给出你在运行该程序时所选用的测试数据及在该测试数据下的运行结果。

【源程序】

#include #include #include float F(float x) #include { float F(float x) return 3*x*x*x-3*x*x+x-1; { } return 3*x*x*x-3*x*x+x-1; float F1(float x) } { float F1(float x) return __________________; { } return 9*x*x-6*x+1; float newtoon(float x) } { float newtoon(float x) float f,f1,x0; { do { ______________; float f,f1,x0; f=F(x0); do { x0=x; f1=F1(x0); f=F(x0); x=______________; f1=F1(x0); }while(_______________); x=x0-f/f1; return x; }while(fabs(x-x0)>1e-5); } return x; void main() } { void main() float x0; { scanf(\ float x0; printf(\result =%.2f\\n scanf(\\ printf(\.2f\\n \

} getch();

} 测试数据:2↙

运行结果:The result =1.00

26.请设计程序,用牛顿迭代法求f(x)=cos(x)-x的近似根,要求精确到10-6。

#include #include

float F(float x) {

return cos(x)-x; }

float F1(float x) {

return -sin(x)-1; }

float newtoon(float x) {

float f,f1,x0; do { x0=x; f=F(x0); f1=F1(x0); x=x0-f/f1;

}while(fabs(x-x0)>1e-6); return x; }

void main() {

float x0;

scanf(\

printf(\ getch(); }

27.已知f(x)=lnx+x2在(1/e, 1)内有唯一的一个实根。请设计程序,用二分法求该近似实根。精确到|f(x)|<0.0001为止。 #include #include float F(float x) {

return log(x)+x*x; } main()

{ float m,n,l,a,b,c,x; a=exp(-1);b=1; m=F(a); n=F(b); do

{ c=(a+b)/2 ; l=F(c); if(m*l<0) b=c;

else a=c;

}while(fabs(l)>=0.0001); x=c;

printf(\ getch(); }

28.请设计程序,用弦截法求程2x3-4x2+3x-6=0在(0,3)内的近似根,直到|f(x)|<0.0001为止。

#include #include float F(float x) {

return 2*x*x*x-4*x*x+3*x-6; } main() {

float a=0,b=3,m,n,l,x; m=F(a); n=F(b); do

{ x=(a*n-b*m)/(n-m); l=F(x); if(l*m>0) a=x; if(l*n>0) b=x;

}while(fabs(l)>=1e-4); printf(\ getch(); }

29.请编辑调试下列程序,观察其运行结果,理解数组名作为函数参数时的作用,并描述程序实验的功能。 【源程序】

#include int fun(int a[],int b[]) {

int i,j=0;

for(i=0;a[i];i++)

{ if(i%2==0)continue ; if(a[i]>10)

b[j++]=a[i]; }

return j; }

void main() {

int a[10]={3,15,32,23,11,4,5,9},b[10]; int i,x; x=fun(a,b) ;

for(i=0;i

printf(\ printf(\}

30.以下程序的功能是从键盘上输入10个整数,并检测整数3是否包含在这些数据中,若包含3,则显示出第一个3出现的位置,程序有些错误,试改正之。 【源程序】

#include #include void main() void main() { { int data[10]; int data[10],j; j=0; j=0; while (j<10) while (j<10) { scanf(\ { scanf(\ j++; j++; } } for(j=0;j<10;j++) for(j=0;j<10;j++) if(data[j]=3) if(data[j]==3) { printf(\is in the position of %d\\n { printf(\is in the position of %d\\n \\ continue; break; } } if(j==10) if(j==10) printf(\ printf(\} getch(); } 31.用以下公式求数列a0,a1,…,a19 a0=0; a1=1; a2=1;

ai= a i-3+ 2ai-2+ ai-1 当 i 大于2时

#include void main()

搜索更多关于: c语言上机实验题 的文档
  • 收藏
  • 违规举报
  • 版权认领
下载文档10.00 元 加入VIP免费下载
推荐下载
本文作者:...

共分享92篇相关文档

文档简介:

} 25.用牛顿迭代法求方程3x3-3x2+x-1=0在x0=2附近的实根。要求: (1)用函数float newtoon(float x)求方程在x附近的根; (2)用函数float F(float x)求x处的函数值,用函数float F1(float x)求f(x)在x处的导数; (3)在主函数中输入x0,调用函数求得方程的近似根(精度要求为10-5),并输出结果。 请完善下列程序,使之完成上述功能。并请以注释的方式在程序的最后给出你在运行该程序时所选用的测试数据及在该测试数据下的运行结果。 【源程序】 #include #include #include float F(float x) #include { float F(floa

× 游客快捷下载通道(下载后可以自由复制和排版)
单篇付费下载
限时特价:10 元/份 原价:20元
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219
Copyright © 云题海 All Rights Reserved. 苏ICP备16052595号-3 网站地图 客服QQ:370150219 邮箱:370150219@qq.com