#include<iostream>
#include<math.h>
using namespace std;
float f(float x)
{
//return exp(x*x); // function f(x)
return (x*x)/(1+x*x*x); //Function f(x)
//return exp(-x*x);
}
int main()
{
int i,n;
float x0,xn,h,sum;
cout<<"Enter no of Intervals: ";
cin>>n;
cout<<"Enter x0 & xn: ";
cin>>x0>>xn;
h=(xn-x0)/n;
cout<<"\nh="<<h;
sum=f(x0)+f(xn);
for(i=0;i<n;i++)
sum+=2*f(x0+i*h);
cout<<"\nIntergral Value="<<(h/2)*sum;
return 0;
}
#include<math.h>
using namespace std;
float f(float x)
{
//return exp(x*x); // function f(x)
return (x*x)/(1+x*x*x); //Function f(x)
//return exp(-x*x);
}
int main()
{
int i,n;
float x0,xn,h,sum;
cout<<"Enter no of Intervals: ";
cin>>n;
cout<<"Enter x0 & xn: ";
cin>>x0>>xn;
h=(xn-x0)/n;
cout<<"\nh="<<h;
sum=f(x0)+f(xn);
for(i=0;i<n;i++)
sum+=2*f(x0+i*h);
cout<<"\nIntergral Value="<<(h/2)*sum;
return 0;
}
No comments:
Post a Comment