int a = 你的数字
int i = 1;
if (a < 0) i++; // 如果负号不计,这行就去除
for (;;)
{
a /= 10;
if (a == 0) break;
i++;
}
cout<
#include
int main()
{
long s;
int n, i = 0;
int a[50];
cout << "输入一个整数:" << endl;
cin >> s;
while(s > 0)
{
a[i] = s%10;
s/=10;
i++;
}
cout << "请选择输出方式:\n"
<< "1.正序输出。\n"
<< "2.逆序输出。" << endl;
cin >> n;
if(n == 1)
for(int j = i; j >0; j--)
cout << a[j-1];
else if(n == 2)
for(int k = 0; k < i; k++)
cout << a[k];
else
cout << "错误!" << endl;
cout << endl;
cout << "位数为" << i << endl;
return 0;
}