#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float x[10],y[10],temp=1,f[10],sum,p;
int i,j,k=0,c,n;
clrscr();
printf("how many record will you enter");
scanf("%d",&n);
for(i=0;i<n;++i)
{
printf("enter the value of x:%d",i);
scanf("%f",&x[i]);
printf("enter the value of f(x%d):",i);
scanf("%f",&y[i]);
}
printf("enter x for finding f(x):");
scanf("%f",&p);
for(i=0;i<n;++i)
{
temp=1;
k=i;
for(j=0;j<n;++j)
{
if(k==j)
continue;
else
temp=temp*((p-x[j])/(x[k]-x[j]));
}
f[i]=y[i]*temp;
}
for(i=0;i<n;i++)
{
sum=sum+f[i];
}
printf("\n\nf(%f)=%f",p,sum);
getch();
}
#include<conio.h>
#include<math.h>
void main()
{
float x[10],y[10],temp=1,f[10],sum,p;
int i,j,k=0,c,n;
clrscr();
printf("how many record will you enter");
scanf("%d",&n);
for(i=0;i<n;++i)
{
printf("enter the value of x:%d",i);
scanf("%f",&x[i]);
printf("enter the value of f(x%d):",i);
scanf("%f",&y[i]);
}
printf("enter x for finding f(x):");
scanf("%f",&p);
for(i=0;i<n;++i)
{
temp=1;
k=i;
for(j=0;j<n;++j)
{
if(k==j)
continue;
else
temp=temp*((p-x[j])/(x[k]-x[j]));
}
f[i]=y[i]*temp;
}
for(i=0;i<n;i++)
{
sum=sum+f[i];
}
printf("\n\nf(%f)=%f",p,sum);
getch();
}
No comments:
Post a Comment