且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

我如何可以通过在C 3位数每个数字重复?

更新时间:2023-02-10 16:13:54

要获得在一个整数我的位置 P 十进制数你可以这样做:

To get the decimal digit at position p of an integer i you would do this:

(i / pow(p, 10)) % 10;

因此​​,从最后一位到第一个数字回路,你可以这样做:

So to loop from the last digit to the first digit, you would do this:

int n = 56; // 056
int digit;    

while(n) {
    digit = n % 10;
    n /= 10;

    // Do something with digit
}

易于修改做准确的3倍。

Easy to modify to do it exactly 3 times.