Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- double f(double x)
- {
- return (1/(1+(x*x)));
- }
- void main()
- {
- double x0,xn,sum,a,temp,h;
- int n,i;
- printf("enter the limits of the integral x0 and xn\n");
- scanf("%lf %lf",&x0,&xn);
- printf("\nenter the number of intervals\n");
- scanf("%d",&n);
- h=(xn-x0)/n;
- sum=f(x0)+f(xn);
- for(i=1;i<=n-1;i++)
- {
- a=x0+(i*h);
- sum=sum+(2*f(a));
- printf("%.6lf \t %.6lf\n",a,f(a));
- }
- temp=(h/2)*sum;
- printf("the answer is %.6lf\n",temp);
- }
- OUTPUT:
- enter the limits of the integral x0 and xn
- 0
- 1
- enter the number of intervals
- 6
- 0.166667 0.972973
- 0.333333 0.900000
- 0.500000 0.800000
- 0.666667 0.692308
- 0.833333 0.590164
- the answer is 0.784241
- Press any key to continue
Advertisement
Add Comment
Please, Sign In to add comment