Write a C++ Program to Reverse a Number using while loop.



Write a C++ Program to Reverse a Number using while loop...

Answer / hr

Solution:
/* C++ Program to Reverse a Number using while loop */
#include<iostream>
using namespace std;
int main()
{
int no,rev=0,r,n;
cout<<"Enter any positive number :: ";
cin>>n;
no=n;
while(no>0)
{
r=no%10;
rev=rev*10+r;
no=no/10;
}
cout<<"
Reverse of a Number [ "<<n<<" ] is :: [ "<<rev<<" ]
";
return 0;
}
Output:
/* C++ Program to Reverse a Number using while loop */
Enter any positive number :: 123456
Reverse of a Number [ 123456 ] is :: [ 654321 ]
Process returned 0

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C++ Interview Questions

What Is Polymorphism in C++ ?

1 Answers   IBS, Impetus, ITC Indian Tobacco Company, Motorola,


How to run C++ program in cmd

0 Answers  


How does stack look in function calls? When does stack overflow? What can you do to remedy it?

0 Answers   Adobe,


Write a C++ Program to find Addition of Two Numbers.

1 Answers  


CDPATH shell variable is in(c-shell)

0 Answers   Siemens,






Write a program that ask for user input from 5 to 9 then calculate the average

0 Answers   IBS,


Discuss about iteration statements in C++ .

0 Answers   Agilent,


What are string library functions(syntax).

0 Answers   Accenture,


What is the difference between virtual functions and pure virtual functions?

1 Answers  


dynamic scoping is

0 Answers   Siemens,


Write a program that can take input from 3 to 8 and calculate the average?

0 Answers   Accenture,


What is static variable and difference between(const char *p,char const *p,const char* const p).

0 Answers   Accenture,


Categories