задачка в билдере с функциями

#1
вот код:


typedef double (*TFun)(double, int);
double fun1(double, int);
double fun2(double, int);
void Out_Rez(TFun, double, double, double, int);
void Out_Mod(TFun,TFun, double, double, double, int);

int main(int argc, char* argv[])
{ double a,b,h;
int n,kod;

puts("Vvedite a,b,h,n");
scanf("%lf%lf%lf%d",&a,&b,&h,&n);

puts("Function :\n 0 - y(x)\n 1 - s(x)\n 2 - |y(x)-s(x)|");
scanf("%d", &kod);
switch(kod){
case 0:Out_Rez (fun1,a,b,h,n); break;
case 1:Out_Rez (fun2,a,b,h,n); break;
case 2:Out_Mod (fun1,fun2,a,b,h,n); break;
}

puts("\nPress any key ... ");
getch();
return 0;
}
//---------------------------------------------------------------------------
void Out_Rez (TFun f,double a,double b,double h,int n){
for(double x=a; x<=b; x+=h)
printf("\n x =%lf f =%lf ",x,f(x,n));
}

void Out_Mod (TFun y,TFun s,double a,double b,double h,int n,){
double r=0;
for(double x=a; x<=b; x+=h){
r=fabs(y(x,n)-s(x,n));
printf("\n x =%lf f =%lf",x,r);
}
}

double fun1( double x, int n){
return (-log(sqrt(1+x*x))+x*atan(x));
}

double fun2(double x,int n){
double s=0;
for(int k=1;k<=n;k++)
s+=pow(-1,k+1)*pow(x,2*k)/(2*k*(2*k-1));
return (s);
}
 
D

dreamer

Гость
#2
Лишняя запятая в списке аргументов процедуры Out_Mod.
 
R

romanriddick

Гость
#3
C++:
 typedef double (*TFun)(double, int);
double fun1(double, int);
double fun2(double, int);
void Out_Rez(TFun, double, double, double, int);
void Out_Mod(TFun,TFun, double, double, double, int);

int main(int argc, char* argv[])
{ double a,b,h;
int n,kod;

puts("Vvedite a,b,h,n");
scanf("%lf%lf%lf%d",&a,&b,&h,&n);

puts("Function :\n 0 - y(x)\n 1 - s(x)\n 2 - |y(x)-s(x)|");
scanf("%d", &kod);
switch(kod){
case 0:Out_Rez (fun1,a,b,h,n); break;
case 1:Out_Rez (fun2,a,b,h,n); break;
case 2:Out_Mod (fun1,fun2,a,b,h,n); break;
}

puts("\nPress any key ... ");
getch();
return 0;
}
//---------------------------------------------------------------------------
void Out_Rez (TFun f,double a,double b,double h,int n)
{		 double x;
for( x=a; x<=b; x+=h)
printf("\n x =%lf f =%lf ",x,f(x,n));
}

void Out_Mod (TFun y,TFun s,double a,double b,double h,int n){
double r=0;double x;
for( x=a; x<=b; x+=h){
r=fabs(y(x,n)-s(x,n));
printf("\n x =%lf f =%lf",x,r);
}
}

double fun1( double x, int n){
return (-log(sqrt(1+x*x))+x*atan(x));
}

double fun2(double x,int n){
double s=0;
int k;
for( k=1;k<=n;k++)
s+=pow(-1,k+1)*pow(x,2*k)/(2*k*(2*k-1));
return (s);
}
все зароботало