///Bismillahir Rahmanir Rahim
///Author:Tanvir Ahmmad
///Dept.CSE,IU,Bangladesh
#include<iostream>
using namespace std;
int main()
{
double up,low,h,arr_y[1009],sum=0;
cout<<"Given function f(x)=1/(1+X)"<<endl<<"Given the upper limit of integration : ";
cin>>up;
cout<<"Given the lower limit of integration : ";
cin>>low;
cout<<"Given the value of h : ";
cin>>h;
int n=(up-low)/h;
cout<<"So the value of n = "<<n<<endl;
for(int i=0; i<=n; i++)
{
arr_y[i]=(1.0/(1.0+(i*h)));
if(i==0) cout<<"X=X0 Y["<<i<<"]="<<arr_y[i]<<endl;
else cout<<"X=X0+"<<i<<"h"<<" Y["<<i<<"]="<<arr_y[i]<<endl;
}
for(int i=1;i<n;i++)
{
if(i%2==1) sum+=(4*arr_y[i]);
else sum+=(2*arr_y[i]);
}
sum+=(arr_y[0]+arr_y[n]);
cout<<"Required value of integration is: "<<(sum*h)/3.0<<endl;
return 0;
}
///Alhamdulillah
Comments
Post a Comment