C Programming Tutorial

Advertisements

Write program to show reverse of a number in C++



       #include<iostream.h>
       #include<conio.h>
       void main()
       {
              int a,num,rev=0; 
              clrscr();

              cout<<"\nEnter any number : "; 
              cin>>num; 

              while(num>0)
              {
                   m = num % 10;                   
                   rev = (rev*10) + m;
                   num = num / 10;
                }
              
              cout<<"\nThe Reverse is : "<<rev;

              getch();
       }

   Output : 

              Enter any number : 4527 
              The Reverse is : 7254




Advertisement