You are on page 1of 1

//C Program for Three point gauss Quadrature method

#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<stdlib.h>
float f(float x)
{
return exp(x);
}
float g(float , float , float);
main()
{
float a=0,b=1.2,x,y,n=3,I=0,f1=0,R[]={0.5555555555555556,0.888888888888888
8,0.5555555555555556},Phi[]={-0.7745966692414834,0.0000000000000000, 0.774596669
2414834};
//a is lower limit, b is upper limit and the function is exp(x)
int i;
for(i=0;i<n;i++)
{
f1=g(a,b,Phi[i]);
I=I+R[i]*f(f1);
}
I=I*(b-a)/2;
printf("The integration of the function is =%.4f",I);
getch();
}
float g(float x, float y, float z)
{
return (y-x)/2*z+(y+x)/2;
}

You might also like