Skip to content

Instantly share code, notes, and snippets.

@Evshved
Last active August 29, 2015 14:10
Show Gist options
  • Select an option

  • Save Evshved/a4c4e4391affcff830c8 to your computer and use it in GitHub Desktop.

Select an option

Save Evshved/a4c4e4391affcff830c8 to your computer and use it in GitHub Desktop.
Using functions
//декларация библиотек
#include <vcl.h> // Visual Component Library
#include <stdio.h> // standard input/output header
#include <conio.h> //console input-output
#include <math.h> //mathematics
#include <stdlib.h> //standard library
#include <alloc.h> //work with dynamic memory
#pragma hdrstop //
#pragma argsused //
typedef double (*Ufun)(double);
double fun1(double);
double fun2(double);
double Out_Rez (Ufun,double);
//îñíîâà
int n;
void main()
{
double a,b,x,h,result_funct1,result_funct2;
int i,sign;
do{
clrscr();
fflush(stdin);
printf(" 1 - Example, others digits -your's inp\n");
scanf("%d",&sign);
if (sign==1) {
a=0.1; b=1.0; h=0.1;
n=10;
}
else {
n=b/h;
n++;
do {
printf( "print a,b,h\n" );
fflush( stdin );
} while(scanf( "%lf%lf%lf",&a,&b,&h) !=3 );
}
printf("\n First function Second function F1(x)- F2(x)|\n ");
for( double x=a; x<=b; x+=h )
{
result_funct1=Out_Rez ( fun1,x );
result_funct2=Out_Rez ( fun2,x );
printf( "\nx=%2.2lf %lf %lf %lf\n",x,result_funct1,
result_funct1,fabs( result_funct1-result_funct2 ) );
}
puts("\nExit - 1, Restart - any key");
} while ( getch() != '1');
}
double fun1( double x){
int k,sup;
double r,s;
r=1;
s=0;
for ( k=1; k<=n; k++ ) {
r=-r*4*x*x/( ( 2*k-1 )*2*k );
s+=r;
}
return s;
}
double fun2 ( double x ) {
return 2*( cos( x )*cos( x )-1 );
}
double Out_Rez ( Ufun f ,double x ) {
return f(x);
}
//---------------------------------------------------------------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment