#include <stdio.h>
int Getfigures(int n) //位数
{
int i;
int Getfigures(int n) //位数
{
int i;
for(i = 1;(n /= 10) ! = 0; i++) do
{ i++;
{
You can also write n/=10 with do whlie;
; ——————————> } while(n != 0)
} return i;
}
void invertedorder(int n) //倒序
{
} return i;
}
void invertedorder(int n) //倒序
{
if( n < 0)
{
printf("-"); //Writable or not, just to change the presentation form
n =-n;
}
do
{
printf("%d ",n%10); //take the remainder Get the one digit
n /= 10; //divide the whole and discard the one digit
} while(n != 0);
printf("\n");
{
printf("-"); //Writable or not, just to change the presentation form
n =-n;
}
do
{
printf("%d ",n%10); //take the remainder Get the one digit
n /= 10; //divide the whole and discard the one digit
} while(n != 0);
printf("\n");
}
void positivesequence(int n) //正序
{ int i;
{ int i;
int j ;
int k = 1 ;
int k = 1 ;
if(n < 0)
{
printf("-");
n=-n;
}
{
printf("-");
n=-n;
}
i = Getfigures (n); //Call the digit function to get the number of digits
for(j = 0; j < i-1; j++)
{ k *= 10; } //Get the value of the minimum digit i, eg : minimum four digits 1000
do
{
printf("%d ",n/k); //take the highest digit
n %= k; //discard the highest digit
k /= 10; //reduce to the smallest i-1 number of digits
} while (n != 0);
printf("\n");
}
for(j = 0; j < i-1; j++)
{ k *= 10; } //Get the value of the minimum digit i, eg : minimum four digits 1000
do
{
printf("%d ",n/k); //take the highest digit
n %= k; //discard the highest digit
k /= 10; //reduce to the smallest i-1 number of digits
} while (n != 0);
printf("\n");
}
int main()
{
printf("%d\n",Getfigures(1234)); //positive integer
invertedorder(1234);
positivesequence(1234);
printf("\n");
printf("%d\n" ,Getfigures(-2598)); //negative integer
invertedorder(-2598);
positivesequence(-2598);
printf("\n");
printf("%d\n",Getfigures(0)); //special value 0
invertedorder(0);
positivesequence(0);
printf("\n");
return 0;
}
{
printf("%d\n",Getfigures(1234)); //positive integer
invertedorder(1234);
positivesequence(1234);
printf("\n");
printf("%d\n" ,Getfigures(-2598)); //negative integer
invertedorder(-2598);
positivesequence(-2598);
printf("\n");
printf("%d\n",Getfigures(0)); //special value 0
invertedorder(0);
positivesequence(0);
printf("\n");
return 0;
}
result: