Write a function, reverseDigitthat takes an integer as a parameter and returns the number with itsdigitsreversed.
Forexample,thevalueofreverseDigit(12345)is54321;thevalueofreverseDigit(5600)is65;thevalueof reverseDigit(7008) is8007;andthe valueof reverseDigit(-532) is-235.
#include <iostream>
using namespace std;
int reverseDigit(int value)
{
  int res=0;
  while(value!=0)
  {
    res*=10;
    res+=value%10;
    value=value/10;
  }
  return res;
}
int main()
{
  cout << reverseDigit(12345) << "\n";
   cout << reverseDigit(5600) << "\n";
   cout << reverseDigit(7008) << "\n";
    cout << reverseDigit(-535) << "\n";
  return 0;
}
Comments
Leave a comment