欢迎来到天天文库
浏览记录
ID:50831385
大小:58.38 KB
页数:1页
时间:2020-03-08
《定积分计算 C语言.pdf》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、#include#includedoublef(doublex)/*函数*/{doubley;y=exp(3*x)+pow(x,7);returny;}doubletixing(doublea,doubleb,longintn)/*梯形法*/{doublesum=(f(a)+f(b))/2,l,x;longi;l=(b-a)/n;x=a;for(i=1;i2、ongintn)/*矩形法*/{doublesum=0,l,x;longi;l=(b-a)/n;x=a;for(i=1;i<=n;i++){x+=l;sum+=f(x);}sum=sum*l;returnsum;}doublexps(doublea,doubleb,longintn)/*辛普森法*/{doublesum=(f(a)+f(b))/2,h,x;longi;h=(b-a)/(2*n);for(i=1;i<=n;i++){x=(2*i-1)*h+a;sum=sum+2*f(x)+f(x+h);}sum=sum*2*h/3;return3、sum;}intmain(){longintn;doublea,b,y;chark;intt=1;while(t){printf("Switch:1.梯形法;2.矩形法;3.辛普森法;4.退出");k=getch();switch(k){case'1':printf("Inputa,b&n:");scanf("%lf%*c%lf%*c%ld",&a,&b,&n);y=tixing(a,b,n);printf("%lf",y);getch();break;case'2':printf("Inputa,b&n:");scanf("%lf%4、*c%lf%*c%ld",&a,&b,&n);y=juxing(a,b,n);printf("%lf",y);getch();break;case'3':printf("Inputa,b&n:");scanf("%lf%*c%lf%*c%ld",&a,&b,&n);y=xps(a,b,n);printf("%lf",y);getch();break;case'4':t=0;break;default:printf("Input1to4!");break;}}}
2、ongintn)/*矩形法*/{doublesum=0,l,x;longi;l=(b-a)/n;x=a;for(i=1;i<=n;i++){x+=l;sum+=f(x);}sum=sum*l;returnsum;}doublexps(doublea,doubleb,longintn)/*辛普森法*/{doublesum=(f(a)+f(b))/2,h,x;longi;h=(b-a)/(2*n);for(i=1;i<=n;i++){x=(2*i-1)*h+a;sum=sum+2*f(x)+f(x+h);}sum=sum*2*h/3;return
3、sum;}intmain(){longintn;doublea,b,y;chark;intt=1;while(t){printf("Switch:1.梯形法;2.矩形法;3.辛普森法;4.退出");k=getch();switch(k){case'1':printf("Inputa,b&n:");scanf("%lf%*c%lf%*c%ld",&a,&b,&n);y=tixing(a,b,n);printf("%lf",y);getch();break;case'2':printf("Inputa,b&n:");scanf("%lf%
4、*c%lf%*c%ld",&a,&b,&n);y=juxing(a,b,n);printf("%lf",y);getch();break;case'3':printf("Inputa,b&n:");scanf("%lf%*c%lf%*c%ld",&a,&b,&n);y=xps(a,b,n);printf("%lf",y);getch();break;case'4':t=0;break;default:printf("Input1to4!");break;}}}
此文档下载收益归作者所有