码迷,mamicode.com
首页 > 其他好文 > 详细

9.5求积分

时间:2015-04-13 18:11:39      阅读:128      评论:0      收藏:0      [点我收藏+]

标签:

技术分享
#include "stdafx.h"
#include <stdlib.h>
#include <stdio.h>
float fun1(float x);
float fun2(float x);
float Integral(float (*f)(float),float a,float b);
int main()
{
 float y1,y2;
 y1 = Integral(fun1,0.0,1.0);
 y2 = Integral(fun2,0.0,3.0);
 printf_s("y1 = %f\n y2 = %f\n",y1,y2);
 system("pause");
 return 0;
}
float fun1(float x)
{
 return 1 + x * x;
}
float fun2(float x)
{
 return x/(1 + x * x);
}
float Integral(float (*f)(float),float a,float b)
{
 float s,h;
 int n = 100,i;
 s = ((*f)(a) + (*f)(b)) / 2 ;
 h = (b - a )/n;
 for(i = 1;i < n;i++)
 {
  s += (*f)(a + i * h);
 }
 return s * h;
}

9.5求积分

标签:

原文地址:http://www.cnblogs.com/joyclub/p/4422477.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!