Implementation Of Striling Formula Using C/C++

#include<iostream.h>
#include<stdio.h>
#include<conio.h>
void main()
{
float ax[100],ay[100],diff[100][5],x,p,h,yp,y1,y2,y3,y4;
int n,i,j;
cout<<"Enter the value of n:";
cin>>n;
cout<<"\nEnter the values:\nx   y\n";
for(i=0;i<=n;i++)
{
cin>>ax[i];
cin>>ay[i];
}
cout<<"\nEnter the value of x for which you want the value of y:";
cin>>x;
h=ax[1]-ax[0];
for(i=0;i<=n-1;i++)
diff[i][1]=ay[i+1]-ay[i];
for(j=2;j<=order;j++)
for(i=0;i<=n-j;i++)
diff[i][j]=diff[i+1][j-1]-diff[i][j-1];
i=0;
do
{
i++;
}
while(ax[i]<x);
i--;
p=(x-ax[i])/h;
y1=p*(diff[i][1]+diff[i-1][1])/2;
y2=p*p*diff[i-1][2]/2;
y3=p*(p*p-1)*(diff[i-1][3]+diff[i-2][3])/6;
y4=p*p*(p*p-1)*diff[i-2][4]/24;
yp=ay[i]+y1+y2+y3+y4;
cout<<"\nWhen x="<<x<<" y="<<yp;
getche();
}

posted under |

0 comments:

Post a Comment

Newer Post Older Post Home

About

Cool na? :) Now Learn How to create one by Clicking here


Followers

About This Blog