/********************************************************************************************************
*
* file name: Zqh_遞迴的列印任意整數.c
* author : keyword2024@163.com
* date : 2024/05/05
* function : 遞迴
* note : 演算法
*
* Copyright (c) 2023-2024 keyword2024@163.com All right Reserved
* ******************************************************************************************************/
#include<stdio.h>
#include<math.h>
void printDigit(int);
void printOut(long);
void printPositive(unsigned long);
int main(void)
{
int a;
printf("Input a num(q to exit):");
while(scanf("%d",&a)==1)
{
printf("Output:");
printOut(a);
printf("\nInpout another num(q to exit):");
}
printf("Byebye!\n");
return 0;
}
//該函式用於輸出任意整數的值
void printOut(long N)
{
if(N>0)
printPositive(N);
else if(N<0)
{
printf("-");
printPositive(abs(N));
}
else
printDigit(N);
}
//該函式用於輸出正整數的值
void printPositive(unsigned long N)
{
if(N>10||N==10)
printPositive(N/10);
printDigit(N%10);
}
//該函式負責輸出小於10的非負整數值
void printDigit(int N)
{
printf("%d",N);
}