面试题:整数转换成字符

#include
using namespace std;


int main()
{
//int num = 12345;
//char string[7];


//itoa(num,string,10); //整型转换成字符
//cout<<"num = "< //for (int i = 0;string[i] != '\0';i++)
//{
// cout< //}
//cout<

int num = 123456;
int intNum[7];
char charNum[7];

int i = 0;
int j = 0;
int k = 0;


cout<<"num = "<

while ((intNum[i ++] = num % 10) > 0)
{
num /= 10;
}

k = i --; //因为最后while循环跳出是num是0,所以i = 7

while(-- i > -1)
{
//charNum[j ++] = (char)(intNum[i] + 48);
charNum[j ++] = intNum[i] + '0';
}


for (int i = 0;i < k;i++)
{
cout< }
cout<

return 0;
}

你可能感兴趣的:(C++)