C Program to Reverse The Number using While loop

C Program to Reverse The Number using While loop

Write C Program to Reverse The Number using While loop

//WAP to reverse the number

#include <stdio.h>

int main()
{
	long int n, ans = 0;
	printf("Enter the number:--> ");
	scanf("%ld", &n);

	while(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