C语言练习:输入一个整数,把该数反过来打出
#include <stdio.h> int main() { int n, rev = 0, remainder; printf("Enter an integer: "); scanf("%d", &n); while (n != 0) { remainder = n % 10; rev = rev * 10 + remainder; n /= 10; } printf("Reversed number = %d", rev); return 0; }
Enter an integer: 2345
Reversed number = 5432
除教程外,本网站大部分文章来自互联网,如果有内容冒犯到你,请联系我们删除!