answersLogoWhite

0

#include<stdio.h>

#include<conio.h>

#include<math.h>

#define f(x) (sin(x*x))

void main()

{

float a,b,h,x,s,n,aaa,h1,h2,p=0.0,p1=0.0,pp,sum,k,i=0.0;

int j=1,co;

clrscr();

printf("\n Plese Enter lower limit :");

scanf("%f",&a);

printf("\n Plese Enter upper limit :");

scanf("%f",&b);

printf("\n Plese Enter the number of Intervales::");

scanf("%f",&n);

h=(b-a)/n; //Calculiting the value of h

printf("The ..................=%f",h);

x=a+h;

s=f(a)+f(b); //Calculiting the First term & last term

while(j<n)

{

if((j%2)==0) //checking even and odd terms

i=i+(2*f(x)); //Calculiting the even terms

else

i=i+(4*f(x)); //Calculiting the odd terms

x=x+h;

j++;

}

i=(h/3)*(i+s); //putting all data in to the formula

printf("\nThe value of the integral is %f",i);

// part is for Error calculation

h1=b-h; h2=a+h;

pp=(7*(f(h2)+f(h1)));

sum=a-h;

k=b+h;

x=a+(2*h);

for(co=2;co<n-2;co++)

{

if(co%2==0)

p=p+(f(x));

else

p1=p1+(f(x));

x=x+h;

}

aaa=(-(h/90))*( ( f(sum)+f(k) )-4*(s) +7*( f(h1) )-(8*p)+(8*p1) );

printf("\nThe Error is= %f",aaa);

getch();

}

User Avatar

Wiki User

13y ago

What else can I help you with?