当前位置: > 写一个用矩形法求定积分的通用函数,分别求正弦,余弦和自然对数幂函数的定积分....
题目
写一个用矩形法求定积分的通用函数,分别求正弦,余弦和自然对数幂函数的定积分.
要能直接运行的代码,能简短的介绍几句更好.

提问时间:2021-01-08

答案
#include
#include
double fun1(double x)
{
return sin(x);
}
double fun2(double x)
{
return cos(x);
}
double fun3(double x)
{
return exp(x);
}
double integral(double a,double b,double (*p)(double))
{
double step=(b-a)/10000;
double x,sum=0;
for(x=a;xsum+=step*(*p)(x);
return sum;
}
main()
{
double a,b,sum,(*p)();
int type;
while(1)
{
printf("1:sin(x) 2:cos(x) 3:exp(x) 0:结束 ");
printf("请选择被积函数的种类(输入种类前的序号): ");
scanf("%d",&type);
while(type<0||type>5)
{
printf("输入的序号不正确,请重新输入:");
scanf("%d",&type);
}
switch(type)
{
case 1:p=fun1;break;
case 2:p=fun2;break;
case 3:p=fun3;break;
case 0:return 0;
}
printf("请输入积分上下限: 下限a:");
scanf("%lf",&a);
printf("上限b:");
scanf("%lf",&b);
sum=integral(a,b,p);
printf("第%d种函数在(%g,%g)范围内的定积分为:%f. ",type,a,b,sum);
}
}
举一反三
已知函数f(x)=x,g(x)=alnx,a∈R.若曲线y=f(x)与曲线y=g(x)相交,且在交点处有相同的切线,求a的值和该切线方程.
我想写一篇关于奥巴马的演讲的文章,写哪一篇好呢?为什么好
奥巴马演讲不用看稿子.为什么中国领导演讲要看?
想找英语初三上学期的首字母填空练习……
英语翻译
版权所有 CopyRight © 2012-2019 超级试练试题库 All Rights Reserved.