C语言你编程:用递归方法实现对一个整数 的 逆序输出

输入输出 示例:Enter a number:1234554321
2024-12-31 08:45:45
推荐回答(2个)
回答1:

#include

void printData(int data)
{
if (data==0)
{
return;
}
printf("%d",data%10);
printData(data/10);
}
int main()
{
int data;
printf("Enter a number:");
scanf("%d",&data);
printData(data);
printf("\n");
return 0;
}
程序如上,可以运行。

回答2:

#include
#include

void print_order_number(unsigned number)
{
printf("%d",number%10);fflush(NULL);
if ( number >= 10 )
{
print_order_number(number/10);
}
}
int main(int argc, char**argv)
{
if ( argc != 2 )
{
printf("Usage: rev_print \n");
exit(0);
}
unsigned number = atol(argv[1]);
print_order_number(number);
return 0;
}