Algorithm Analysis
We will divide the number by 10 until we get 0. On each iteration, we print the last digit of the current number.
Algorithm Implementation
Read the input number .
scanf("%lld", &n);
If = 0, then we print 0.
if (n == 0) printf("0");
Print the digits of the number in reverse order.
while(n > 0) { printf("%d",n%10); n /= 10; } printf("\n");
Algorithm Implementation – reverse
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; char s[100]; int main(void) { gets(s); reverse(s,s+strlen(s)); puts(s); return 0; }