#include<iostream.h>
#include<conio.h>
#include<math.h>
double a[20][20],v;
int n,i,j;
void table()
{
cout<<"\nEnter the number of terms=";
cin>>n;
cout<<"\nEnter "<<n<<" no. x's value=\n";
for(i=0;i<n;i++)
{
cout<<"\nx"<<i<<"=";
cin>>a[i][0];
}
cout<<"\nEnter "<<n<<" no. y's value=\n";
for(i=0;i<n;i++)
{
cout<<"\ny"<<i<<"=";
cin>>a[i][1];
}
for( j=2;j<n;j++)
{
int c=n;
for(i=n;i>0;i--)
{
a[c][j]=a[i][j-1]-a[i-1][j-1];
c--;
}
}
clrscr();
cout<<"\n Newton's Backward formula=\n";
for(i=0;i<n;i++)
{
for(j=0;j<=i+1;j++)
cout<<"\t"<<a[i][j];
cout<<"\n";
}
float x;
cout<<"\nEnter the values of x=";
cin>>x;
v=(x-a[n-1][0])/(a[1][0]-a[0][0]);
cout<<"\nv="<<v;
}
int fact(int x)
{
if(x==0 || x==1)
return 1;
else
return x*fact(x-1);
}
void main()
{
clrscr();
float m=1,b[20],y;
table();
for(i=0;i<n-1;i++)
{
m=m*(v+i);
b[i]=m;
}
y=a[n-1][1];
float h=a[1][0]-a[0][0];
cout<<"\nh="<<h;
for(i=0;i<n;i++)
{
y=y+(a[n-1][i+2]*b[i])/fact(i);
}
cout<<"\nThe result is="<<y;
}
#include<conio.h>
#include<math.h>
double a[20][20],v;
int n,i,j;
void table()
{
cout<<"\nEnter the number of terms=";
cin>>n;
cout<<"\nEnter "<<n<<" no. x's value=\n";
for(i=0;i<n;i++)
{
cout<<"\nx"<<i<<"=";
cin>>a[i][0];
}
cout<<"\nEnter "<<n<<" no. y's value=\n";
for(i=0;i<n;i++)
{
cout<<"\ny"<<i<<"=";
cin>>a[i][1];
}
for( j=2;j<n;j++)
{
int c=n;
for(i=n;i>0;i--)
{
a[c][j]=a[i][j-1]-a[i-1][j-1];
c--;
}
}
clrscr();
cout<<"\n Newton's Backward formula=\n";
for(i=0;i<n;i++)
{
for(j=0;j<=i+1;j++)
cout<<"\t"<<a[i][j];
cout<<"\n";
}
float x;
cout<<"\nEnter the values of x=";
cin>>x;
v=(x-a[n-1][0])/(a[1][0]-a[0][0]);
cout<<"\nv="<<v;
}
int fact(int x)
{
if(x==0 || x==1)
return 1;
else
return x*fact(x-1);
}
void main()
{
clrscr();
float m=1,b[20],y;
table();
for(i=0;i<n-1;i++)
{
m=m*(v+i);
b[i]=m;
}
y=a[n-1][1];
float h=a[1][0]-a[0][0];
cout<<"\nh="<<h;
for(i=0;i<n;i++)
{
y=y+(a[n-1][i+2]*b[i])/fact(i);
}
cout<<"\nThe result is="<<y;
}
No comments:
Post a Comment