codescracker


c

C Program to Reverse Number



« Previous Program Next Program »


Reverse Number in C

To reverse a number in C programming, you have to ask to the user to enter the number. Start reversing the number, first make a variable say rev of same type and place 0 to rev variable initially, and make one more variable say rem. Now place the modulus of the number to rem and place rev*10+rem to the rev now divide the number with 10 and continue until number will become 0

C Programming Code to Reverse Number

Following C program ask to the user to enter any number to find the reverse, then display the result on the screen :

/* C Program - Reverse Number */
		
#include<stdio.h>
#include<conio.h>
void main()
{
	clrscr();
	int num, rev=0, rem;
	printf("Enter a number : ");
	scanf("%d",&num);
	while(num!=0)
	{
		rem=num%10;
		rev=rev*10+rem;
		num=num/10;
	}
	printf("Reverse = %d",rev);
	getch();
}

When the above c program is compile and executed, it will produce the following result:

c program to reverse number

Same Program in Other Programming Language

You may also like same program in other programming languages:


« Previous Program Next Program »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test