Beta Coder

Learn code like Beta Coder.

Breaking

Monday, September 14, 2020

C Program to Reverse a number

Reverse a number

Reverse a number
In this program we learn how to reverse a number provided by user using C.
C program to reverse a number
// Reverse a number
#include<stdio.h>
#include<conio.h>
void main()
{
	int n, r, rev = 0;
	clrscr();
	printf("\n Enter a number : ");
	scanf("%d",&n);
	do
	{
		r = n % 10;
		rev = (rev * 10) + r;
		n = n / 10;
	}while(n != 0);
	printf("\n The reverse number : %d",rev);
	getch();
}
OUTPUT:
   Enter a number : 185
   The reverse number : 581

No comments:

Post a Comment