小编pap*_*ton的帖子

无法在C中的for循环的第一次迭代中读取

我正在尝试创建一个能够计算拉格朗日多项式的程序,但我遇到了可能是一个微不足道的问题.我给出了一些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)

c arrays for-loop scanf

1
推荐指数
1
解决办法
73
查看次数

标签 统计

arrays ×1

c ×1

for-loop ×1

scanf ×1