#include<stdio.h>
#include<conio.h>
#include<math.h>
float f(float x)
{ return (1/(1+pow(x,2)));
}
void main()
{int i,n;
float a,b,h,I,sum=0.0;
clrscr();
printf("enter the values of lower and upper limits 'a' and 'b'");
scanf("%f%f",&a,&b);
printf("enter the no. of subinetrvals n");
scanf("%d",&n);
h=(b-a)/n;
sum=f(a)+f(b);
for(i=1;i<n;i++)
{if(i%2==0)
sum=sum+2*f(a+i*h);
else
sum=sum+4*f(a+i*h);
}
I=(h/3)*sum;
printf("the value is %f:",I);
getch();
}
#include<conio.h>
#include<math.h>
float f(float x)
{ return (1/(1+pow(x,2)));
}
void main()
{int i,n;
float a,b,h,I,sum=0.0;
clrscr();
printf("enter the values of lower and upper limits 'a' and 'b'");
scanf("%f%f",&a,&b);
printf("enter the no. of subinetrvals n");
scanf("%d",&n);
h=(b-a)/n;
sum=f(a)+f(b);
for(i=1;i<n;i++)
{if(i%2==0)
sum=sum+2*f(a+i*h);
else
sum=sum+4*f(a+i*h);
}
I=(h/3)*sum;
printf("the value is %f:",I);
getch();
}
No comments:
Post a Comment