C program to reverse a number

In this tutorial, we will see simple c program to reverse a number.

Output:

Enter an number: 162
Reversed Number : 261

In this program, we are reversing number as follow:

  • Check if num is not equal to 0, in while loop
  • Find the remainder of num%10 which will be last digit.
  • We are putting last digit to first place of revNum¬†using revNum=revNum*10+remainder
  • Dividing num by 10 to reduce num by one digit.
  • Repeat above step, until num is not equal to 0.

That’s all about C program to reverse a number.

Leave a Reply

Your email address will not be published. Required fields are marked *