My Blog List

Monday, December 16, 2019

Reverse number using cpp.

Reverse number using cpp.

        In this tutorial we learn how to print reverse number of any digit using cpp programming language.
A number contained any digit then by following technique we convert its into reverse order.
        suppose we take a 3 digit integer number and we want to print its into the reverse order then,the number is mod,add reminder and divide operation until number is 0.If number reach to 0 then terminate the execution.

example:

      number is 123
step 1:
       //here we taking a mod of number i.e 3
       mod=123%10
step 2:
       //here we add the reminder into mod that multiplied by 10
       reminder=reminder*10+mod
step 3:
       //finally number dividation.
       number=number/10

code:

#include<iostream.h>
#include<conio.h>
void main()
{
    int num,mod,reminder=0,i;
    clrscr();
    cout<<"\nEnter any 3 digit number:";
    cin>>num;
    while(num!=0)
    {
        mod=num%10;
        reminder=reminder*10+mod;
        num=num/10;
    }
    cout<<"\nReverse number:"<<reminder;
    getch();
}


Output:




You may also like:
Dynamic Memory Management in cpp.
Manipulators in cpp. 
This is the program constructor overloding in cpp 

No comments:

Post a Comment

Multiple Inheritance in C++.

     In this tutorial Multiple Inheritance in c++. On the basis of Inheritance concept the another type of inheritance is the Multiple I...