Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

c++ reverse integer

#include <iostream>
using namespace std;
 
int main()
{
    int num;
    
    //Input a number
    cout << "Enter a Number: ";
    cin >> num;
    
    //Initialize rev with 0
    int rev=0;
    
    //Append digits in reverse order
    while(num>0){
        rev = rev*10 + num%10;
        num = num/10;
    }
    
    cout << "Reverse: " << rev;
    return 0;
}
Source by pencilprogrammer.com #
 
PREVIOUS NEXT
Tagged: #reverse #integer
ADD COMMENT
Topic
Name
7+4 =