04/11/2015

C++ Program To Print A Reverse Number Using Loop

Problem :- Write A C++ Program To Print A Reverse Order Of Any Number Using Loop

Logic :- Very Simple Logic Just Divide a number by 10 and then proceed for next statement 

Sum=0
sum=sum*10+X

Note :- Always remember Do Not try to print the reverse Digit always try to modified 
Like you can also solve the problem

while(n!=0)
{
rev=n%10;
System.out.print("Reversed Number = "+reverse);
n=n/10
}
but in this way number is printing actually not reversing .


If you Understood then try to solve given problem .

Check this Geeksforgeeks Solution For " Reverse digit "

Solution :-

#include<iostream>
using namespace std;
int main()
{
 //By-Ghanendra Yadav
 int n,x,sum=0;

 cout<<"Enter The Number To Be Reverse: \n";
 cin>>n;

 while(n>0)
 {
  x=n%10;
  sum=sum*10+x;
  n=n/10;
 }
 cout<<"\nThe Reverse Number is "<<sum;
}

Output:-

C++ Program To Print A Reverse Number Using Loop

Previous Post
Next Post

post written by:

Hi, I’m Ghanendra Yadav, SEO Expert, Professional Blogger, Programmer, and UI Developer. Get a Solution of More Than 500+ Programming Problems, and Practice All Programs in C, C++, and Java Languages. Get a Competitive Website Solution also Ie. Hackerrank Solutions and Geeksforgeeks Solutions. If You Are Interested to Learn a C Programming Language and You Don't Have Experience in Any Programming, You Should Start with a C Programming Language, Read: List of Format Specifiers in C.
Follow Me

0 Comments: