首页 > 其他分享 >逆序输出整数

逆序输出整数

时间:2022-12-14 21:22:47浏览次数:38  
标签:输出 return reverse 10 int 整数 while print 逆序

 

def reverse(b: int):
    while b // 10:
        print(b % 10)
        b //= 10
    print(b)


reverse(1234)
reverse(8)
reverse(0)

 

def reverse(b: int) -> int:
    if b < 10:
        return b
    t = 0
    while b // 10:
        t = t * 10 + b % 10
        b //= 10
    t = t * 10 + b
    return t


print(reverse(1234))
print(reverse(78))
print(reverse(0))

 

#include <stdio.h>

int main(void) {
    int b;
    printf("input integer: ");
    scanf("%d", &b);
    do {
        printf("%d", b % 10);
    } while ((b /= 10) != 0);
    return 0;
}

 

标签:输出,return,reverse,10,int,整数,while,print,逆序
From: https://www.cnblogs.com/dissipate/p/16983567.html

相关文章