-
Notifications
You must be signed in to change notification settings - Fork 1
/
lag.c
42 lines (42 loc) · 1.15 KB
/
lag.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include<stdio.h>
main()
{
float x[100],y[100],a,s=1,t=1,k=0;
int n,i,j,d=1;
printf("\n\n Enter the number of the terms of the table: ");
scanf("%d",&n);
printf("\n\n Enter the respective values of the variables x and y: \n");
for(i=0; i<n; i++)
{
scanf ("%f",&x[i]);
scanf("%f",&y[i]);
}
printf("\n\n The table you entered is as follows :\n\n");
for(i=0; i<n; i++)
{
printf("%0.3f\t%0.3f",x[i],y[i]);
printf("\n");
}
while(d==1)
{
printf(" \n\n\n Enter the value of the x to find the respective value of y\n\n\n");
scanf("%f",&a);
for(i=0; i<n; i++)
{
s=1;
t=1;
for(j=0; j<n; j++)
{
if(j!=i)
{
s=s*(a-x[j]);
t=t*(x[i]-x[j]);
}
}
k=k+((s/t)*y[i]);
}
printf("\n\n The respective value of the variable y is: %f",k);
printf("\n\n Do you want to continue?\n\n Press 1 to continue and any other key to exit");
scanf("%d",&d);
}
}