Explanation :
- We take a integer input from user .
- Use for loop and apply condition until number is zero.
- In for loop we apply math condition to reverse whole number. In math its called modulus.
- When loop is end we receive reverse of input .
( if you input is 1234 you receive 4321 )
#include<iostream> using namespace std; int main() { int number, reverse = 0; cout<<"Please Input a Number to Reverse and press Enter: "; cin>> number; // Taking Integer Input for( ; number!= 0 ; ) { reverse = reverse * 10; reverse = reverse + number%10; number = number/10; } cout<<"Reversed Number is: "<<reverse<<endl; system("pause"); }
Image of Code :
0 comments:
Post a Comment