以下为程序,输入的数为任意数(只要不溢出就可以)
____________________________________________________
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>
int getDigitLength(int number)
{
int flag;
if (0 == number) { flag = 0; }
else
{
int i = 1;
flag = 1;
while (!(i <= number && i*10 >= number))
{
i = i * 10;
flag++;
}
}
return flag;
}
int main(int argc, char *argv[])
{
int num;
int len;
printf("please enter number (0 <= number <= %d): ", INT_MAX/3);
scanf("%d",&num);
len = getDigitLength(num);
//printf("%d length: %d\n", num, len);
if (0 == len)
{
printf("old number is %d\n", num);
printf("new number is %d\n", num);
}
else
{
printf("old number is %d\n", num);
num = num / (int)pow(10, len-1) + (num % (int)pow(10, len-1)) * 10;
printf("new number is %d\n", num);
}
return 0;
}
_________________________________________________________
另外送上一个可以实现输入任意位数的程序,这个扩展性好(C++)
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char *argv[])
{
string number;
cout << "please enter number:";
cin >> number;
int len;
int i;
len = number.size();
cout << "old number :";
for (i = 0; i < len; i++)
cout << number[i];
cout << endl;
cout << "new number :";
for (i = 1; i < len; i++)
cout << number[i];
cout << number[0];
cout << endl;
return 0;
}
温馨提示:内容为网友见解,仅供参考