Program:
#include<stdio.h>
#include<math.h>
void main()
{
float y, x[20],f[20],sum,pf;
int I,j,n;
printf(“enter the value of n”); scanf(“%d”,&n);
printf(“enter the value to be found”); scanf(“%f”,&y);
printf(“enter the values of xi’s & fi’s”); for(i=0;i<n;i++)
{
pf=1;
for(j=0;j<n;j++)
{
If(j!=i)
pf *= (y-x[j])/(x[i] – x[j]);
}
sum += f[i] *pf;
}
printf(“\nx = %f ”,y);
printf(“\n sum =%f ”,sum);
getch();
}
Input/Output:
Enter the value of n 4
Enter the value to be found 2.5
Enter the values for xi’s & fi’s
1 1
2 8
3 27
4 64
X = 2.500000
Sum = 15.625000
VIVA QUESTIONS
1) Define storage class ?
Ans: Storage class specifiers inform the complier how to store the variable; the storage clas specifiers in the c language are :
auto, register, static,extern,typedef
Data structures using Java
#include<stdio.h>
#include<math.h>
void main()
{
float y, x[20],f[20],sum,pf;
int I,j,n;
printf(“enter the value of n”); scanf(“%d”,&n);
printf(“enter the value to be found”); scanf(“%f”,&y);
printf(“enter the values of xi’s & fi’s”); for(i=0;i<n;i++)
{
pf=1;
for(j=0;j<n;j++)
{
If(j!=i)
pf *= (y-x[j])/(x[i] – x[j]);
}
sum += f[i] *pf;
}
printf(“\nx = %f ”,y);
printf(“\n sum =%f ”,sum);
getch();
}
Input/Output:
Enter the value of n 4
Enter the value to be found 2.5
Enter the values for xi’s & fi’s
1 1
2 8
3 27
4 64
X = 2.500000
Sum = 15.625000
VIVA QUESTIONS
1) Define storage class ?
Ans: Storage class specifiers inform the complier how to store the variable; the storage clas specifiers in the c language are :
auto, register, static,extern,typedef
No comments:
Post a Comment