Write a C++ Program to Reverse a Number using while loop.
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 |
What is Copy Constructor?
What is C++11?
What is the difference between public, private, and protected inheritance?
Tell How To Check Whether A Linked List Is Circular ?
Identify the error in the following program. include<iostream> using namespace std; void main() { int num[]={1,2,3,4,5,6}; num[1]==[1]num ? cout<<"Success" : cout<<"Error"; }
what is the difference between a pointer and a reference?
0 Answers Amazon, Blue Star, C DAC,
Write a C++ Program to find Addition of Two Numbers.
What is static variable and difference between(const char *p,char const *p,const char* const p).
How to convert integer to string in C++
What is pass by value & reference.
What are the advantages/disadvantages of using #define?
What are string library functions(syntax).