码迷,mamicode.com
首页 > 编程语言 > 详细

C语言编程 递归方式实现打印一个整数的每一位

时间:2019-04-11 19:23:41      阅读:251      评论:0      收藏:0      [点我收藏+]

标签:缩小   int   51cto   思想   数字   clu   sys   can   https   

主要思想依旧是取位和调用数字的缩小
参照https://blog.51cto.com/14232799/2377396
源代码:

#include<stdio.h>
#include<stdlib.h>
void print(int n)
{
    if (n > 9)
    {
        print(n / 10);//数的缩小
    }
    printf("%-4d", n%10);//取位
}
int main()
{
    int number;
    printf("请输入要打印的数\n");
    scanf("%d", &number);
    print(number);
    system("pause");
    return 0;
}

C语言编程 递归方式实现打印一个整数的每一位

标签:缩小   int   51cto   思想   数字   clu   sys   can   https   

原文地址:https://blog.51cto.com/14232799/2377407

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!