Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
Idea:
To achieve a print out of every arbitrary integer, as long as 10 to take the remainder of the integer addition, but according to the order to print out, it is necessary to first integer division until 10; implemented recursively, in Output ( int n) function, integer greater than 9, call the Output (int n) function, but this time in addition to the parameter is an integer 10, and the addition up to an integer less than 10, a first print, and then continue to return to the previous level, until we have all of the number of prints.
Source:
#include<stdio.h>
#include<windows.h>
void Output(int n)
{
if (n > 9){
Output(n/10);
}
printf("%d ", n % 10);
}
void main()
{
int n;
printf("请输入您想要分别输出每一位的数> ");
scanf_s("%d", &n);
Output(n);
printf("\n");
system("pause");
}
operation result: