Showing posts with label write a program to reverse a number. Show all posts
Showing posts with label write a program to reverse a number. Show all posts

Sunday, 1 October 2017

write a program to reverse a number in c++

C++ Program to Reverse a Number

You must have basic knowledge of  C++ programming language and variable  , while loop and if..ealse and for loop

What is reverse Number?

This reverse of number means reverse the all position of all is also know as the reverse.
 we entered value from user then we reverse an number using the while loop in c++,

Example of reverse number

87654321 this is reverse number

Example.C++ Program to reverse an number

#include <conio.h>
using namespace std;
int main ( )
  int onum,reminder,sum=0,num;
cout<<"Please enter the number";

   //this condition is use to check num not = zero. 

   reverse = (reverse*10) + reminder;
   num = num / 10;

cout <<onum<<"is reverse number";

return 0;
getch ();

Please enter the number           ;
123456789                                       :
987654321 is reverse number    ---------

In above program ,a positive number enter by the user which value is stored in onum variable.

After that,we copied onum into num variable

we using the while loop for unit number num  !  = 0 is false

Inside the while loop , last digit is different  from num by the operation digit = num % 10;. This digit is cubed and added to the variable sum.

Finally reverse digit is displayed on the monitor

You should have basic programming knowledege
like syntax and variable and if else statement or for loop that is must learn before starting
the program.
Which people want to learn programming language.this website very beneficial for those people.