cpp program to reverse the number

The program to reverse an integer number in the cpp programming language.For understanding the program you should learn the first following topic.

while loop

input method

output method


Code:

#include <iostream>

using namespace std;


int main()

{

int num,reversednumber=0;

cout<<" enter the number "<<endl;

cin>>num;

while(num!=0)

{

reversednumber=reversednumber*10+num%10;

num=num/10;

}


cout<<" reversed number = "<<reversednumber<<endl;

    return 0;

}


here, firstly enter the number through the input method then use while loop.In the loop, the terminal condition is num!=0 , modulus the num separate the one digit and add in the reverse number at its unit place by multiple by 10.

At the end of the loop,(num/10)divide the number by 10 to reduce the one-digit till the no digit in the num.

In the last of the program, display the reversednumber on the screen.

If you face any problem in the understanding of the above example, kindly writes in the below comment section. we will help you entertain you as soon as possible

Comments

Popular posts from this blog

Diferrence between flutter and react native

Flutter Widgets

Flutter layout