300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > 用矩形法求定积分 分别求sin x dx cos x dx e exp x;

用矩形法求定积分 分别求sin x dx cos x dx e exp x;

时间:2020-03-05 02:43:02

相关推荐

用矩形法求定积分 分别求sin x dx  cos x dx e exp x;

// jifen.cpp : 定义控制台应用程序的入口点。

//

#include "stdafx.h"

float integral(float(*p)(float),float a,float b,int n)

{

int i;

float x,h,s;

h=(b-a)/n;

x=a;

s=0;

for(i=0;i<n;i++)

{

x+=h;

s+=(*p)(x)*h;

}

return (s);

}

float fsin(float s)

{

return sin(s);

}

float fcos(float s)

{

return cos(s);

}

float fexp(float s)

{

return exp(s);

}

int _tmain(int argc, _TCHAR* argv[])

{

float a1,b1,a2,b2,a3,b3,c,(*p)(float);

int n=20;

printf("input a1, b1\n");

scanf("%f,%f",&a1,&b1);

printf("input a2, b2\n");

scanf("%f,%f",&a2,&b2);

printf("input a3, b3\n");

scanf("%f,%f",&a3,&b3);

p=fsin;

c=integral(p,a1,b1,n);

printf("the integral of sin(x) is:%f\n",c);

p=fcos;

c=integral(p,a2,b2,n);

printf("the integral of cos(x) is:%f\n",c);

p=fexp;

c=integral(p,a3,b3,n);

printf("the integral of exp(x) is:%f\n",c);

system("PAUSE");

return 0;

}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。