Program to Display Reverse Numbers

Reverse Number

We will write a C program to display the reverse of the given number and the number will be entered by the user. This will help to understand the basic structure of programming. In this program , we will display the reverse of given numbers easily by using proper syntax and algorithms.

Program to Display Reverse Numbers

Working of Program :

In the program, we will require some numbers from the user to display the reverse of the given numbers.

Syntax for while() loop:

while(condition)
{
    // Statements
    // Increment / Decrement
}

Problem 1

Write a program to reverse the given number.

  • Firstly, we have to enter the any number.
  • Then print that reverse number.

Code

Run
#include<stdio.h>
int main ()
{
  int n = 4567, reverse = 0, rem;
  while (n != 0)
    {
      rem = n % 10;
      reverse = reverse * 10 + rem;
      n /= 10;
    }
  printf ("Reversed number = %d", reverse);
  return 0;
}

Output

Reversed number = 7654

Note:

In the following program we will display the reverse number using do-while() loop.

Syntax for do – while() loop:

do
{
    // Statements
    // Increment / Decrement
}
while(condition)

Problem 2

Write a program to display the reverse number using do – while() loop.

  • Firstly, we have to enter the any number.
  • Then print that number is  palindrome or not.

Code

Run
#include<stdio.h>
int main ()
{
  int n = 8967, a, r, s = 0;
  a = n;
  do
    {
      r = n % 10;
      s = s * 10 + r;
      n = n / 10;
    }
  while (n > 0);
  printf ("\nThe Reverse Number = %d",s);
  return 0;
}

Output

The Reverse Number = 7698

Prime Course Trailer

Related Banners

Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription

Get over 200+ course One Subscription

Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others

Checkout list of all the video courses in PrepInsta Prime Subscription

Checkout list of all the video courses in PrepInsta Prime Subscription