The following data is given Write a Ccode to Obtain the poly
Solution
1)
#include<stdio.h>
#include<math.h>
#define MAX 100
void main()
{
int number,i,j ;
char ch;
double x[MAX],f[MAX],functionpoint,lf,sum,xinterpoint ;
do
{
while((number<=0) || (number>200))
{
printf(\"Please provide total number of points\");
scanf(\"%d\",&number);
if (number<=0)
printf(\"Please enter a positive number for interpolation point\");
if (number>100)
printf(\"Number is out of range\");
}
printf(\"Please enter value of x and corresponding function\");
for(i=1;i<=number;i++)
{
printf(\"Please enter value for x%d= \",i);
scanf(\"%lf\",&x[i]);
printf(\"Please enter the value of function of x f(x%d)= \",i);
scanf(\"%lf\",&f[i]);
}
printf(\"Please enter the value of x at which you want to calculate the interpolation\");
scanf(\"%lf\",&xinterpoint);
sum=0.0;
for(i=1;i<=number;i++)
{
lf=1.0;
for(j=1;j<=number;j++)
{
if(i!=j)
lf=lf*(xinterpoint-x[j])/(x[i]-x[j]);
}
sum=sum+lf*f[i];
}
functionpoint=sum;
printf(\"The values are %lf\",xinterpoint,functionpoint);
printf(\"Please enter y to continue and n to stop\");
ch=(char)getche();
}while(ch==\'Y\' || ch==\'y\');
getch();
}
