⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lagrange.cpp

📁 计算数值方法的几个源程序,牛顿法,三角法,追赶法等
💻 CPP
字号:
#include <stdio.h>
#include <stdlib.h>
void main( void )
{
 int  n;
 float *x = NULL;
 float *y = NULL;
 float xFound;
 float yGet = 0.0;
 float   yGetTemp = 1.0;
 printf("请输入你要输入的n的个数:");
 scanf("%d", &n);
 printf("请输入已知x的值(如:10 29 23 ……): ");
 x = (float *)malloc(sizeof(float) * n);
 for (int client = 0; client < n; client++)
  scanf("%f", (x + client));
 
 printf("\n");
 printf("请输入已知Y的值(如:23 23 23 ……): ");
 y = (float *)malloc(sizeof(float) * n);
 for (client = 0; client < n; client++)
  scanf("%f", (y + client));
 
 printf("\n请输入要求的x的值: ");
 scanf("%f", &xFound);
 int temp;
 for (client = 0; client < n; client++)
 {
  for (temp = 0; temp < n; temp++)
  {
   if (temp == client)
    continue;
   else
    yGetTemp *= ( (xFound - *(x + temp)) / ( *(x + client) - *(x + temp)));
  }
  
  yGet += (yGetTemp * (*(y + client)));
  yGetTemp = 1.0;
 }
 printf("\nThe result is:%f\n", yGet);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -