#include <stdio.h>
#include <conio.h>
#include <math.h>
#define N 5
double X[N+1]={0.40,0.55,0.65,0.80,0.90,1.05};
double Y[N+1]={0.41075,0.57815,0.69675,0.88811,1.02652,1.25382};
double b[N+1][N+1],xx[N],aa[N+1];
void main ()
{
int i,m,n,j,k;
double s;
clrscr();
for(k=0;k<=N;k++)
{ j=0; s=1;
for(i=0;i<=N;i++)
if(i!=k){xx[j++]=X[i];s*=X[k]-X[i];}
b[k][0]=-xx[0];b[k][1]=1;
for(m=1;m<N;m++)
{
b[k][m+1]=b[k][m];
for(n=m;n>0;n--)
b[k][n]=b[k][n-1]-b[k][n]*xx[m];
b[k][0]=-xx[m]*b[k][0];
}
for(i=0;i<=N;i++)
aa[i]+=Y[k]/s*b[k][i];
}
printf("P(x):\n");
for(i=N;i>0;i--)
{
printf("(%f)*X^%d+ ",aa[i],i);
puts("");
}
printf("(%f)\n",aa[0]);
getch();
}