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