Answer to Question #210451 in C++ for Zuhaib Saleem

Question #210451

Create a class named Random Program and add a static function named reverse that will accept integer e.g. 17425 and return the reverse (52471


1
Expert's answer
2021-06-24T12:06:45-0400
#include <iostream>

class RandomProgram
{
  public:

    static int reverse(int value)
    {
        int result = 0;

        while(value > 0)
        {
            result = 10 * result + value % 10;
            value /= 10;
        }
        
        return result;
    }
};

int main()
{
    std:: cout << 17425 << " --> " << RandomProgram::reverse(17425) << "\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