The following program reverses user input. However, for numbers with trailing zeroes, the zeroes are 'ignored' when printing the reversed number.
#include<stdio.h>
int main(void)
{
int n, reversedNumber = 0, remainder;
printf("Enter an integer: ");
scanf("%d", &n);
while(n != 0)
{
remainder = n%10;
reversedNumber = reversedNumber*10 + remainder;
n /= 10;
}
printf("Reversed Number = %d
", reversedNumber);
return 0;
}
Since the integer length of the user input is unknown, how can we print all the trailing zeros for example:
Enter an Integer: 3000
Reversed Number = 0003
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…