PP 3

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

#include<stdio.

h>
#include<math.h>
double F(double x){
return (exp(x));}
double int_F(double x,double y){
return (exp(y)-exp(x));}
double intSimpson(double(*Func)(double), double a, double b, int N){
int i;
double h,intF;
h=(b-a)/(N);
intF=0;
for (i=0;i<=N-1;i++)
{intF=intF+(h/6)*((*Func)(a+i*h)+4*(*Func)(a+(i+0.5)*h)+(*Func)(
a+(i+1)*h));}
return intF;}
int main(){
double a,b,h;
int N,i;
printf("Enter the lower limit:\n");
scanf("%lf", &a);
printf("Enter the upper limit:\n");
scanf("%lf", &b);
printf("Enter the number of division:\n");
scanf("%d", &N);
FILE *fout;
fout=fopen("pp3.dat","w");
for (i=0;i<=200;i++){
N+=i;
h=(b-a)/(N);
fprintf(fout,"%E\t%E\t%E\t%E\t%E\t%E\n", h,log(h),fabs(int_F(a,b
)-intSimpson(F,a,b,N)),log(fabs(int_F(a,b)-intSimpson(F,a,b,N))),int_F(a,b),intS
impson(F,a,b,N));}
fclose(fout);
return 0;
}

You might also like