C Program to Reverse a Number using for loop

In this tutorial, we will write a reverse number in C using for loop. Before that, you may go through the following topics in C.


C program to reverse a number using for loop

This is a reverse number program in C using for loop where the program takes the input from the user. And then iterating through for loop, the program calculates the reverse of a number and then finally displays the result.

#include <stdio.h>

int main()
{
  int num, rev = 0, rem;

  //User Input
  printf("Enter the Number: ");
  scanf("%d", &num);

  for (; num != 0; num = num / 10)
  {
    rem = num % 10;
    rev = rev *10 + rem;
  }

  printf("Reversed number: %d", rev);
  return 0;
}

Output:

Enter the Number: 1234
Reversed number: 4321

As you can see the initialization part in for loop is left empty and only the condition checking and increment/decrement is filled within “()” in reverse number in c using for loop.