Q:

C++ Program To Print A Reverse Number Using Loop

belongs to collection: Loop Programs In C ++Programming

0

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 .

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include<iostream>
using namespace std;
int main()
{

 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:

Enter The Number To Be Reverse: 

12345

The Reverse Number is 54321

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C++ Program Generate Truth Table Of X Y+C Using Lo... >>
<< C++ Program To Print A Table Using For Loop...