正序输出:
#include <stdio.h>
#include <stdlib.h>
void print(int x)
{
if (x <= 9)
{
printf("%d", x);
}
else
{
print(x / 10);
printf("%d", x % 10);
}
}
int main()
{
int a = 1234;
print(a);
system("pause");
return 0;
}
运行结果:
逆序输出:
#include <stdio.h>
#include <stdlib.h>
int A(int x)
{
int tmp=0;
while(x!=0)
{
tmp = tmp * 10 + x % 10;
x /= 10;
}
return tmp;
}
int main()
{
int a = 1234;
int ret = A(a);
printf("%d\n", ret);
system("pause");
return 0;
}
运行结果: