Write a function to reverse an integer. Use this in main

#include <stdio.h>
int main() 
{
      int n, result;
      printf("Enter an integer: ");
      scanf("%d", &n);
      result=reverse_number(n);
      printf("Reversed number = %d", result);
      return 0;
}
int reverse_number(int num)
{
int reverse = 0, remainder;
while (num != 0)
{
    remainder = num % 10;
    reverse = reverse * 10 + remainder;
    num /= 10;
  }
  return(reverse);
}

0 Comments:

Post a Comment