C Program to Reverse a Number | Reverse Number Program in C | CodeTextPro

C program to reverse a number. This program reverses the number entered by the user and then prints it on the screen. For example, if a user will enter 12345 as input then 54321 will be printed as output. In our program, we use the modulus (%) operator to obtain the digits of a number. To invert a number look at it and write it from opposite directions or the output of the program is a number obtained by writing the original number from right to left.



Reverse Number

C program to find the reverse of a number

#include<stdio.h>

#include<conio.h>

main()
{
int n, r;

printf("Enter The Number:\n");

scanf("%d",&n);

for(r=0; n>0; n=m/10)

{

r=r*10;

r=r+(n%10);

}

printf("The Reverse Number is:\n %d",r);

getch();

}



Output of Program:

C Program to Reverse The Number

C Program to Reverse the number using recursion


#include <stdio.h>
long reverse(long);
int main()

{

   long n, r;
   
   scanf("%ld", &n);
   r = reverse(n);
   printf("%ld\n", r);
   return 0;

}
long reverse(long n) 

{

   static long r = 0;
   
   if (n == 0)

      return 0;
   
   r = r * 10;

   r = r + n % 10;

   reverse(n/10);

   return r;

}



Output of Program:

Reverse Number Using Recursion

Post a Comment

1 Comments