Reverse a number in c++


#include <iostream>

using namespace std;

int main()
{
    
    int originalNumber, reverseNumber = 0 , reminder = 0 ;
    cout<<"Enter a number ";
    std::cin >> originalNumber;
    
    while(originalNumber != 0){
        reminder = originalNumber % 10;
        reverseNumber = reverseNumber*10 + reminder;
        originalNumber = originalNumber/10;
    }
    
    cout<< reverseNumber;

    return 0;
}

Reverse a String in c++

#include <iostream>

using namespace std;

int main()
{
    string reverseString = "reverse";
    
    int lengthOfString = reverseString.length();
    
    for (int i = 0; i < lengthOfString/2; i++) {
        /* code */
        swap(reverseString[i] , reverseString[lengthOfString - i -1 ]);
        
    }
    
    std::cout << reverseString;

    return 0;
}