# why the output is wrong?

asked May 7, 2020
#include<math.h>
float f(float x)
{
return 1/(1+x*x);
}
int main()
{
float a,b,h,x,sum=0.0;
int i,n;
printf("Enter lower limit and upper limit:\n");
scanf ("%f%f",&a,&b);
printf("Enter number of intervals:\n");
scanf("%d",&n);
h=(b-a)/n;
for(i=1;i<=n-1;i++)
{
x=a+(i*h);
if(i%2==0)
sum=sum+2*f(x);
else
sum=sum+4*f(x);
}
sum=(h/3)*(sum+f(a)+f(b));
printf("The value of integral:%f\n",sum);
return 0;
}                               //????//

answered May 7, 2020 by (140 points)

add this line at the top of the code

`#include<stdio.h> `

answered May 7, 2020 by (150 points)
You have asked a wrong question
answered May 8, 2020 by (190 points)

#include<stdio.h> // <--  a small error
#include<math.h>
float f(float x)
{
return 1/(1+x*x);
}
int main()
{
float a,b,h,x,sum=0.0;
int i,n;
printf("Enter lower limit and upper limit:\n");
scanf ("%f%f",&a,&b);
printf("Enter number of intervals:\n");
scanf("%d",&n);
h=(b-a)/n;
for(i=1;i<=n-1;i++)
{
x=a+(i*h);
if(i%2==0)
sum=sum+2*f(x);
else
sum=sum+4*f(x);
}
sum=(h/3)*(sum+f(a)+f(b));
printf("The value of integral:%f\n",sum);
return 0;
}                               //????//

answered May 12, 2020 by (6,380 points)
#include<stdio.h>
#include<math.h>
float f(float x)
{
return 1/(1+x*x);
}
int main()
{
float a,b,h,x,sum=0.0;
int i,n;
printf("Enter lower limit and upper limit:\n");
scanf ("%f%f",&a,&b);
printf("Enter number of intervals:\n");
scanf("%d",&n);
h=(b-a)/n;
for(i=1;i<=n-1;i++)
{
x=a+(i*h);
if(i%2==0)
sum=sum+2*f(x);
else
sum=sum+4*f(x);
}
sum=(h/3)*(sum+f(a)+f(b));
printf("The value of integral:%f\n",sum);
return 0;
}