#include
using namespace std ;
//求一个数有多少位
int GetDigitCount(int n)
{
int c = 0 ;
while (n)
{
n /= 10 ;
++c ;
}
return c ;
}
int main(void)
{
int num = 12345 ;
//取得数字的位数
int c = GetDigitCount(num) ;
//动态分配数组
int* a = new int[c] ;
//用数字各位填充数组,注意倒着填充
for (int i = c - 1; i >= 0; --i)
{
a[i] = num % 10 ;
num /= 10 ;
}
//输出数组中的数据
for (int i = 0; i < c; ++i)
{
cout << a[i] ;
}
cout << endl ;
delete a ;
a = NULL ;
system("pause") ;
return 0 ;
}