C++ Int to Array without Libs

C++ Int to Array without Libs

本文关键字:without Libs Array to Int C++      更新时间:2023-10-16

大家早上好!我如何将int a = 325;转换为数组int b[2],没有lib?我指的是b[0] = 3; b[1] = 2; b[2] = 5;

再见

执行如下操作:

int x = a;
int i = 0;
while (x > 0)
{
    b[i++] = x % 10;
    x /= 10;
}

你可以这样做

int i=100;
for(int x=0;x<3;x++)
{
    b[x]=a/i;
    a=a%i;
    i=i/10;
}