C Program to Reverse the Number using While Loop

C Program to Reverse the Number using While Loop

Write a C program to reverse the given number using While Loop.

//WAP TO REVERSE THE NUMBER

#include <stdio.h>

int main()
{
	long int n;
	long int ans = 0;

	printf("Enter the number that you want to reverse:--> ");
	scanf("%ld", &n);

	while(n != 0)
	{
		long int digit = n % 10;   //to find the last digit of the number
		ans = ans*10 + digit;
		n = n/10;
	}

	printf("The reverse of the number is : %ld",ans);

	return 0;
}