Write a C Program to check Reverse Number || C Programming Tutorials

Опубликовано: 25 Апрель 2026
на канале: Learning and Teaching Coding
1,361
22

====== Logic behind the code===========

First, we will find the last digit of input number, and then we will store it into a variable and remove it.

Now again, we will see that the second last digit will become the last digit. So again we will pick the last digit of the number and then append it with the digit which we have calculated and stored previously in ‘reverseNum’ variable.

We will follow the same approach for all digit of a number. Once we apply the same logic for each digit of number then at last ‘reverseNum’ variable will contain a reverse number.

=========== Explanation of reverse program===============

In the above program I have taken a static number 321 which is assigned in variable ‘number’. Here I am not taking the value from users.

We have one more integer variable ‘reverseNum’ that will store value each time when we find last digit of the number.

We can say that ‘number’ is storing original value and ‘reverseNum’ variable will store the value after reverse.

Now using while loop here we are checking that value of ‘number’ should not be 0. If already zero then we can’t perform any operation on it and when ‘number’ is not zero, in body of while loop we are finding last digit of the number and adding it to the same number by multiplying 10 and then storing it in reverse variable.

And at last dividing original number by 10 to remove the last digit of the number. As we already collected it in reverse variable.

I hope Guys you have understand it well.

#LearningandTeachingCoding
#CProgrammingTutorials
#CPrograms