Reverse of a number

Program to reverse of a number

C program to print reverse of a number

We can reverse a number in c using loop and arithmetic operators. In today’s program, we are getting numbers as input from the user and reversing that number through some lines of code.

#include <stdio.h>
void main() {
    int num, rev = 0, rem;
printf("\n\t\t\t...Welcome To EduNews.Tech... ");
    printf("\n\nEnter an integer: ");
    scanf("%d", &num);
    while (num != 0) {
        rem = num % 10;
        rev = rev * 10 + rem;
        num /= 10;
    printf("Reversed number = %d", rev);
printf("\n\n\n\n\t\t\tThankyou for Joining Us !");
    printf("\n\t\t\t!Regards EduNews !");

Program Output:

reverse number

Program Explanation:

  • In this program, we take input from the user. Then the while loop is used until num != 0 is false (0).
  • In each iteration of the loop, the remainder when num is divided by 10 is calculated and the value of num is reduced by 10 times.
  • Inside the loop, the reversed number is computed using:
    rev = rev*10 + rem;

I hope this post helps you to understand the Reverse of a number and its implementation in C programming language.

Keep coding 🙂

1 thought on “Reverse of a number”

Leave a Reply

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