在这段代码中,我试图让用户输入一个 int 值 (x),然后在下面的 while 循环中比较这个值:while(k < x)。当我这样做时,我的程序崩溃了。
int main()
{
long int sum = 0;
long int i = 1;
long int j = 2;
long int k = 0;
int x = 0;
printf("This program will sum up all of the evenly valued terms from the
Fibionacci sequence, up until the\n user-specified highest term value.\n");
printf("Set this limit: ");
scanf("%d",x);
while(k < x)
{
k = i + j;
if(k%2==0)
sum +=k;
i = j;
j = k;
}
printf("The sum of all of the evenly valued terms of the Fibionacci sequence up until the value %d is %d",x,sum);
return 0;
}