Advertisement

Program to reverse a number in C++

 In this article I will show how to reverse a number in C++ || Code with abuzar 



Today we are learning about how to reverse a number in C++ but why ? and what is use of reverse number ? 

Reverse number are those type of number which is opposite the number means that 12345 and reverse is 54321 this is the reverse number uses of this number is only to know how logic works , when you code in C++ there is no use in some case you have to used this logic so the main purpose of this knowing that how logic work in C++ .


Example :

#include<iostream>
using namespace std;
int main()
{
int n , reversenumber = 0 
int remainder ;

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

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

cout<<"Reverse number "
<<reversenumber<<endl; 

 return 0;
}

  

When the above code is compiled and run it then the output is 

Output :

Enter an integer 12345

Reverse number is 54321 


Please ! write comment if you find anything incorrect in this article 

This article is contributed by Mohd abuzar . If you like code with abuzar or want to contribute with us so mail at - abuzar.abuzar.mohd325@gmail.com.

Post a Comment

0 Comments