📄 lagrange.c
字号:
#include<stdio.h>
#define N 1000
void main()
{
int i,j,k,p;
float x[N],l[N],f[N],m[N];
float y,L;
printf("Please put in the number of the sum of the crunodes:");
scanf("%d",&k);
printf("Please put in the values of the crunodes and the function values in order:\n");
for(i=0;i<k;i++)
scanf("%f%f",&x[i],&f[i]);
printf("Please put in the value that you want to get:");
scanf("%f",&y);
for(i=0;i<k;i++)
{
for(j=0,l[i]=1;j<k;j++)
{
if(j==i)
m[j]=1;
else
m[j]=(y-x[j])/(x[i]-x[j]);
l[i]=l[i]*m[j];
}
}
for(i=0,L=0;i<k;i++)
L=L+l[i]*f[i];
printf("The function value you want to get is:%f\n",L);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -