Give a positive integer: 1 which is determined by several orders; 2 digit outputs each; 3 each digit output in the reverse order, for example, the original number of 321, 123 to be output....

// count n is a digit
@ algorithm: discarding each digit (n / = 10)
int GetFigures (int n)
{
int I;
for (I = 0; n = 0; I ++!)
{
N = n / 10;
}
return I;
}
// sequentially outputs, 1234-> 1234
@ algorithm: calling a function of the number of bits required to confirm that the number is a positive integer several; determined by the circulation, to obtain the highest positive integer bit should be divisible
void PrintOrder (int n-)
{
int I = GetFigures (n-);
int m =. 1;
for (int J =. 1; J <I; J ++)
{
m * = 10;
}
int tmp;
the while ( ! n-= 0)
{
tmp = n-/ m;
n-m =%;
m / = 10;
the printf ( "% D", tmp);
}
the printf ( "\ n-");
}

// reverse order output, 123-> 321
@ algorithm: obtained digit, digit discard
void PrintReverse (n-int)
{
int tmp;
for (int I =. 1; n-= 0; I ++!)
{
Tmp % n-10 =;
n-/ = 10;
the printf ( "% D", tmp);
}
the printf ( "\ n-");
}

int main()
{
printf("%d\n",GetFigures(123456));
printf("%d\n",GetFigures(-123456));
PrintOrder(1234);
PrintReverse(123);
}

Published 13 original articles · won praise 3 · Views 636

Guess you like

Origin blog.csdn.net/weixin_43873172/article/details/87938206