游客 已登陆
(0) 未知
笔行证
257310
昵称
kuan
笔贝
Score1
加为好友
发送短信
就是可以查看颜色的。比如#FFCCFF你不知道是什么颜色。你就可以用它来查看。同样你看到你喜欢的颜色。可...
什么??晕死啊!!
好 啊
好东西。。等学完了再来看看。。。
学了点东西了。。呵呵
注意,上面代码,有一些显示不出来.过些天,哥德会把笔客完善一下.到时.所有代码就应该没错了.
这个函数是计算积分的.算法思想:求积分我们可以求他的面积,,沿X轴分成n份,计算n份的面积再相加.
f...
float integral(float(*p)(float),float a,float b,int n)
{int i;
float x,h,s;
h=(b-a)/n;
x=a;
...
^_^ 好东西啊
阿宽又一新作
呵呵 厉害啊 说得很清楚了
厉害 呵呵 写得简单清晰
不错啊
^_^ 写得不错哦
支持下
访问计数: 21274本文:383 今天:1 本月 383
2006-11-11 晴
出处或者来源:C程序设计(第二版)
#include<stdio.h>
#include<math.h>
void main()
{float a1,b1,a2,b2,a3,b3,c,(*p)(float); //指向函数的指针
int n=20;
float integral(float(*p)(float),float a,float b,int n);
float fsin(float);
float fcos(float);
float fexp(float);
printf("Input a1,b1:");
scanf("%f,%f",&a1,&b1);
printf("Input a2,b2:");
scanf("%f,%f",&a2,&b2);
printf("Input a3,b3:");
scanf("%f,%f",&a3,&b3);
p=fsin;
c=integral(p,a1,b1,n);
printf("The integral of sinx is:%f
",c);
p=fcos;
c=integral(p,a2,b2,n);
printf("The integral of cosx is:%f
",c);
p=fexp;
c=integral(p,a3,b3,n);
printf("The integral of expx is:%f
",c);
}
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=1;i<=n;i++)
{
x+=h;
s+=(*p)(x)*h;
}
return s;
}
float fsin(float x)
{return (float)sin(x);} /*类型强制转换由double转为float*/
float fcos(float x)
{return (float)cos(x);}
float fexp(float x)
{return (float)exp(x);}
运行结果:
Input a1,b1:0,1
Input a2,b2:-1,1
Input a3,b3:1,2
The integral of sinx is:0.480639
The integral of cosx is:1.681539
The integral of expx is:4.788514
Press any key to continue.
# posted by kuan @ 2006-11-11 21:44:23 评论(0)
这个函数是计算积分的.算法思想:求积分我们可以求他的面积,,沿X轴分成n份,计算n份的面积再相加.
float integral(float(*p)(float),float a,float b,int n)
//这里的第一个参数是定义一个指向函数的指针,
下面有一句语句
s+=(*p)(x)*h;//其中的(*p)(x)也就是函数的调用了,.
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=1;i<=n;i++)
{
x+=h;
s+=(*p)(x)*h;
}
return s;
}
这一段看不懂啊.