static int MyPow(int nData);
static int MyPow(int nData)
{
int nRet = 1;
int i = 0;
for(i = 0; i < nData; i++)
{
nRet = nRet * 10;
}
return nRet;
}
static int CheckNumber(int nInput)
{
int nRet = 0;
int i = 0;
int number1 = 0;
int number2 = 0;
for(i = 5; i >= 0; i--)
{
if((nInput / MyPow(i)) != 0)
{
break;
}
}
switch(i)
{
case 5:
number1 = (nInput / 1000);
number2 = (nInput % 1000);
break;
case 4:
number1 = (nInput / 100);
number2 = (nInput % 100) * 10;
break;
case 3:
number1 = (nInput / 100);
number2 = (nInput % 100);
break;
case 2:
number1 = (nInput / 10);
number2 = (nInput % 10) * 10;
break;
case 1:
number1 = (nInput / 10);
number2 = (nInput % 10);;
break;
case 0:
number1 = (nInput % 10);
number2 = 0;
break;
default:
break;
}
nRet = number1 + number2;
printf("number1:%d,number2:%d,nRet:%d\r\n",number1,number2,nRet);
return nRet;
}
int main(int argc,char *argv[])
{
int nInput;
int nOutput;
printf("\r\n please input a number < 1000000 \r\n");
scanf("%d",&nInput);
do
{
nOutput = CheckNumber(nInput);
nInput = nOutput;
}while(nOutput >= 10);
return 0;
}