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 |
Without using third variable write a code to swap two numbers.
When would you use a pointer? A reference?
Can we provide one default constructor for our class?
what is friend function in C++?
What is the difference between public, private, and protected inheritance?
Write a C++ Program to Reverse a Number using while loop.
What is Advantage and Use of THIS pointer in C++ – Scenarios?
Explain function prototypes in C++.
What does it mean to take the address of a reference?
What does it mean to declare a function or variable as static?
explain the term 'resource acquisition is initialization'?
In C++ what do you mean by Inheritance?