Post 在 while 循环中与乘法一起使用的递增

Post incrementation used with multiplication in while loop

奇数数组是这样分组的:first号是第一组,接下来的2号是第二组,接下来的3号是第三组组等。

群组:

  1. 1
  2. 3 5
  3. 7 9 11
  4. 13 15 17 19
  5. 21 23 25 27 29

现在我想找出给定的数字是否是一组中数字的总和,并找到该组的订单号。

我写了下一个代码:

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int k;
    scanf("%d", &k);

    int x = 1;
    while( x * x * x < k )
        x++;

    if( x * x * x != k )
        x = 0;

    printf("%d", x);
    return 0;
}

然后我尝试将 while 循环更改为下一个:

while( x * x * x++ < k )
    ;

该程序无法运行,我在 codeblocks 中收到下一个警告:

operation on 'x' may be undefined

为什么它不起作用?

x * x++ 的行为是未定义。这是因为您实际上是在 未排序的 步骤中读取和写入 x;乘法在 C.

中不是 序列点

不要在 C 语言中这样做。出于礼貌,您的编译器会警告您。其他编译器可能会吃掉你的猫。