#include<stdio.h>
#include<conio.h>
int factorial(int);
float ufunc(int,float);
void main()
{
float x[20],y[19][19],u,result=0,temp=1,reqX;
int i,j,n,s;
printf("enter how many numbers you want to add (max 20) :: ");
scanf("%d",&n);
printf("enter date :: \n");
for(i=0;i<n;i++)
{
printf("x[%d] : ",i);
scanf("%f",&x[i]);
printf("y[%d] : ",i);
scanf("%f",&y[0][i]);
}
printf("enter the value of x for that you want to the value of y :: ");
scanf("%f",&reqX);
for(i=1;i<n;i++)
{
for(j=0;j<n-i;j++)
{
y[i][j]=y[i-1][j+1]-y[i-1][j];
}
}
u=reqX-x[0];
u=u/(int)(x[1]-x[0]);
result=result+y[0][0];
for(j=1;j<n;j++)
{
temp=ufunc(j-1,u)*y[j][0];
result=result +temp/factorial(j);
}
printf("\n\n result is :: %f",result);
getch();
return;
}
int factorial(int num)
{
int i,res=1;
for(i=1;i<=num;i++)
{
res=res*i;
}
return res;
}
float ufunc(int num,float u)
{
int i;
float res=1;
for(i=0;i<=num;i++)
{
res=res*(u-i);
}
return res;
}
#include<conio.h>
int factorial(int);
float ufunc(int,float);
void main()
{
float x[20],y[19][19],u,result=0,temp=1,reqX;
int i,j,n,s;
printf("enter how many numbers you want to add (max 20) :: ");
scanf("%d",&n);
printf("enter date :: \n");
for(i=0;i<n;i++)
{
printf("x[%d] : ",i);
scanf("%f",&x[i]);
printf("y[%d] : ",i);
scanf("%f",&y[0][i]);
}
printf("enter the value of x for that you want to the value of y :: ");
scanf("%f",&reqX);
for(i=1;i<n;i++)
{
for(j=0;j<n-i;j++)
{
y[i][j]=y[i-1][j+1]-y[i-1][j];
}
}
u=reqX-x[0];
u=u/(int)(x[1]-x[0]);
result=result+y[0][0];
for(j=1;j<n;j++)
{
temp=ufunc(j-1,u)*y[j][0];
result=result +temp/factorial(j);
}
printf("\n\n result is :: %f",result);
getch();
return;
}
int factorial(int num)
{
int i,res=1;
for(i=1;i<=num;i++)
{
res=res*i;
}
return res;
}
float ufunc(int num,float u)
{
int i;
float res=1;
for(i=0;i<=num;i++)
{
res=res*(u-i);
}
return res;
}
0 Comments