Untitled

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

#include<iostream.

h>
#include<math.h>
#include<conio.h>
float f(float);
void main()
{
float h , k1=0.0 , k2=0.0 , k3=0.0 , k4=0.0;
float x[20],y[20];
int n,i;
clrscr();
cout<<"\nEnter number of parts";
cin>>n;
cout<<"\nEnter lower and upper limits :";
cin>>x[0]>>x[n];
y[0] = f(x[0]);
h = (x[n] - x[0]) / n;
for(i=1 ; i < n ; i++)
{ x[i] = x[0] + i * h ;
y[i] = f(x[i]);
if(i % 2 == 0)
k1 = k1 + 12 * y[i];
else
k1 = k1 + 32 * y[i];
}
y[n] = f(x[n]);
float ans = ((2*h)/45)*(7*y[0]+7*y[n]+k1+k2+k3+k4);
cout<<"\nAnswer= "<<ans;;
getch();
}
float f(float x)
{ float g;
g = log(x);
return g;
}
OUTPUT :Enter number of parts : 6
Enter lower and upper limits : 4 5.2
Answer= 1.81427

You might also like