c语言不懂如何运算的

那个while(x)里面的几行运算代码什么含义,题目可以看上个提问的问题


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll a[30],x;
    a[0]= 1;
    for (int i = 1; i<= 20; i++)
        a[i]= a[i-1]*i;
    while (~scanf("%lld",&x))
    {
        int ans = 0, i = 20;
        while (x)
        {
            ans += x / a[i];
            x = x % a[i];
              i--;
           printf("%d\n", ans);
        }
    }
    return 0;
}

scanf()的返回值是成功赋值的变量数量, 发生错误时返回EOF.


~符号是按位取反(是“按位”哦),针对字节变量,把字节中每位取反,相当于和FFH进行异或运算。
这里当没有输入的时候,scanf()就返回-1,~-1=0就结束了。
和while(scanf("%lld",&n)!=EOF)一样