📄 5_16.cpp
字号:
#include<iostream.h>
#include<iomanip.h>
float f1(float x);//函数声明
float f2(float x);//函数声明
int main()
{
float integral(float (*p)(float),float a,float b);//函数声明
float s1,s2;
s1=integral(f1,0,1);//函数调用
s2=integral(f2,0,1);//函数调用
cout<<"s1="<<setw(5)<<setprecision(5)<<s1<<endl;
cout<<"s2="<<setw(5)<<setprecision(5)<<s2<<endl;
return(0);
}
float integral(float (*p)(float),float a,float b)
{
float sum;
sum=0.5*(b-a)*(p(a)+p(b));//利用指针调用函数
return(sum);
}
float f1(float x)
{
float s;
s=2*x+3;
return(s);
}
float f2(float x)
{
float s;
s=x*x-3*x+5;
return(s);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -