C Program to Reverse Number using For Loop
Write a Program to Reverse Number using For Loop
// C Program to Reverse Number using For Loop #include <stdio.h> int main() { long int n, ans = 0; printf("Enter the number:--> "); scanf("%ld", &n); for(; n!=0; ) { int remainder = n % 10; //2 //2 //4 ans = ans*10 + remainder; //2 //22 //224 n = n / 10; //42 //4 } printf("The answer is %ld",ans); return 0; }
Output:
Enter the number:--> 456
The answer is 654