我正在尝试创建一个能够计算拉格朗日多项式的程序,但我遇到了可能是一个微不足道的问题.我给出了一些x和y值,我应该使用这些值来近似某个其他x的函数.变量nodes指的是给出的x和y值对的数量.
我无法在x值的第一次迭代中读取,并且它直接跳过读取y值.即它只是打印x(0)然后y(0)而不让我输入x(0)的任何内容.对于第一个循环之后的任何循环,这不是问题.任何帮助,将不胜感激.
#include "stdio.h"
#include "math.h"
#define SIZE 40
int main(){
// Defining variables and arrays
int i, j, nodes;
float nodex[SIZE], nodey[SIZE], appx;
// Find how many nodes there are
printf("How many nodes are being referenced?\n");
scanf("%d", &nodes);
// Find what number we are approximating for x
printf("For what value of x are we approximating?\n");
scanf("%d", &appx);
for(i=0 ; i < nodes ; i++)
{
printf("\nEnter x(%d)", i);
scanf("%f", &nodex[i]);
printf("\nEnter y(%d)", i);
scanf("%f", &nodey[i]);
}
}
Run Code Online (Sandbox Code Playgroud)