Answer to Question #265534 in C++ for Usama

Question #265534

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.



1
Expert's answer
2021-11-24T00:41:51-0500
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS