write a program to print the reverse of given number
The code for this program is as follows:
cout <<"Enter the number: ";
cout <<"\nReverse of "<<a<<" is: "<<rev;
#include<iostream.h> used for input/output of data
#include<conio.h> provides several functions like clrscr(), getch() etc.
After that in main() function we have declared a variables no, rev=0, r, a; after that we have used clrscr(); function to clear the scree when program will run. It will clear the previous output from any program. Now we have used the cout function that shows message “Enter the number :”; and when we enter any number then this number is read by cin function and assign to no variable.
Here we have assigned the value of no to the a variable. Here we have used a while loop. Here we have used the condition no>0 means loop will be continued while the value of no variable is greater than 0. Inside the loop, first of all we have to calculate the remainder of the no then assigned to the r variable. Because when we use no%10 ; this will give the last digit of the number. After that we have used the rev*10+r; here we add the value of r with rev*10 and assign to rev. now we have to get the next digit so that we have used the no/10 and assign it to no. This loop will be continued till the condition will not become false.
The output is as follows: