Search
 
SCRIPT & CODE EXAMPLE
 

CPP

C++ Program to Reverse an Integer

#include <iostream>
using namespace std;

int main() {

  int n, reversed_number = 0, remainder;

  cout << "Enter an integer: ";
  cin >> n;

  while(n != 0) {
    remainder = n % 10;
    reversed_number = reversed_number * 10 + remainder;
    n /= 10;
  }

  cout << "Reversed Number = " << reversed_number;

  return 0;
}
Comment

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;
}
Comment

c++ reverse digits in integer

reverse integers
Comment

PREVIOUS NEXT
Code Example
Cpp :: counting sort c++ 
Cpp :: Appending a vector to a vector in C++ 
Cpp :: convert int to binary string c++ 
Cpp :: string reversal 
Cpp :: input 2d vector c++ 
Cpp :: parallelize for loop c++ 
Cpp :: allow cross origin 
Cpp :: c++ reverse integer 
Cpp :: chrono start time in c++ 
Cpp :: how to make a random number in c++ 
Cpp :: set precision with fixed c++ 
Cpp :: length of string c++ 
Cpp :: struct and array in c++ 
Cpp :: random number generator c++ between 0 and 1 
Cpp :: c++ 2d vector assign value 
Cpp :: c++ call method in same class 
Cpp :: c++ simple projects 
Cpp :: sleep c++ 
Cpp :: ray sphere intersection equation 
Cpp :: convert string to lpwstr 
Cpp :: iterate vector in reverse c++ 
Cpp :: calloc c++ 
Cpp :: priority queue c++ 
Cpp :: 2d array c++ 
Cpp :: loop through array c++ 
Cpp :: stack implementation using class in c++ 
Cpp :: log in c++ 
Cpp :: c++ get line 
Cpp :: c++ namespace 
Cpp :: c++ capture screen as pixel array 
ADD CONTENT
Topic
Content
Source link
Name
1+7 =