Problem E: C语言习题 矩形法求定积分


Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 423  Solved: 269
[Submit][Status][Web Board]

Description

写一个用矩形法求定积分的通用函数,分别求

 

(说明: sin,cos,exp已在系统的数学函数库中,程序开头要用#include<cmath>)。

Input

输入求sin(x) 定积分的下限和上限
输入求cos(x) 定积分的下限和上限
输入求exp(x) 定积分的下限和上限

Output

求出sin(x)的定积分
求出cos(x)的定积分
求出exp(x)的定积分

Sample Input

0 1
0 1
0 1

Sample Output

The integral of sin(x) is :0.48
The integral of cos(x) is :0.83
The integral of exp(x) is :1.76

HINT



主函数已给定如下,提交时不需要包含下述主函数



/* C代码 */

int main()

{

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

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

    float fsin(float);

    float fcos(float);

    float fexp(float);

    int n=20;

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

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

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

    p=fsin;

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

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

    p=fcos;

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

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

    p=fexp;

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

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

    return 0;

}





/* C++代码 */

int main()

{

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

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

    float fsin(float);

    float fcos(float);

    float fexp(float);

    int n=20;

    cin>>a1>>b1;

    cin>>a2>>b2;

    cin>>a3>>b3;

    cout<<setiosflags(ios::fixed);

    cout<<setprecision(2);

    p=fsin;

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

    cout<<"The integral of sin(x) is :"<<c<<endl;

    p=fcos;

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

    cout<<"The integral of cos(x) is :"<<c<<endl;;

    p=fexp;

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

    cout<<"The integral of exp(x) is :"<<c<<endl;

    return 0;

}

[Submit][Status][Web Board]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值