Compute the Reverse of an Integer, 12345 becomes 54321 - C Data Type

C examples for Data Type:int

Introduction

If a given integer is 12345, then its reverse is 54321.

Demo Code

#include <stdio.h>

int main()// w  ww. ja  v a  2  s . c om
{
      long int counter = 1234, temp, remainder, reverse;
 
      temp = counter;
      reverse = 0;

      while (temp > 0){
         remainder = temp % 10;
         reverse = reverse * 10 + remainder;
         temp /= 10;
      }

      printf("The reverse of %ld is %ld.\n", counter, reverse);
      return 0;
}

Result


Related Tutorials