Title description: Reverse a four-digit output
Input description: one line, enter an integer n (1000<=n<=9999)
Output description: For each set of input, reverse the corresponding four-digit output
Code
#include<stdio.h>
int main()
{
int n = 0;
scanf("%d", &n);//输入一个数
while (n)//直到n=0跳出循环
{
printf("%d", n % 10);//n取余后得到最后一位数,输出这个数
n=n / 10;//去掉n最后一位数
}
return 0;
}
result output
Code Analysis:
If we want to input 1234, then it should output 4321.