Program to Reverse Number in C

Here you will learn how to reverse a number in C.

Program

#include<stdio.h>
 
int main()
{
	long n,rev=0,d;
	printf("Enter any number:");
	scanf("%ld",&n);
	
	while(n!=0)
	{
		d=n%10;
		rev=(rev*10)+d;
		n=n/10;
	}
	
	printf("The reversed number is %ld",rev);
 
	return 0;
}

Output

Enter any number:16789
The reversed number is 98761

Leave a Comment

error: Alert: Content is protected!!