My code is-
#include<iostream>
#include<cmath>
using namespace std;
double func(double t,double f)
{
return 1.0/sqrt(1.0-pow((sin(t/2.0)*sin(f)),2));
}
double simp(double(*f)(double),double a,double b,int n)
{
int i;
double sum,ini,h;
i=0;sum=0.0;ini=0.0;
h=(b-a)/n;
ini+=(*f)(a);
ini+=(*f)(b);
for(i=1;i<=n/2.0;i++)
{
ini+=4*((*f)(a+((2*i)-1)*h));
ini+=2*((*f)(a+((2*i)-2)*h));
}
sum=(1.0/3.0)*h*ini;
return sum;
}
int main()
{
int i=10000;
double a=0.0,b=M_PI/2.0;
cout<<"The integral is "<<simp(func,a,b,i)<<endl;
return 0;
}
But when I complied this code it shows -
In function ‘int main()’:
error: invalid conversion from ‘double (*)(double, double)’ to ‘double (*)(double)’
error: initializing argument 1 of ‘double simp(double (*)(double), double, double, int)’
I am a beginner in function pointer . So please suggest me how do I call the function to get rid of this error??

New Topic/Question
Reply




MultiQuote






|