c++ programs examples

C++ Program to reverse a number using function with return type and arguments.

c++ programs examples
/* 13. Write a program to reverse a number using function with return type
       and arguments. */

 #include<iostream.h>
 #include<conio.h>
 int reverse(int);
 void main()
 {
  int no,rev;
  clrscr();
  cout<<"Enter a number"<<endl;
  cin>>no;
  rev=reverse(no);
  cout<<"The reversed number is="<<rev<<endl;
  getch();
  }
 int reverse(int no)
 {
  int rem,rev=0;
  while(no>0)
  {
   rem=no%10;
   rev=rev*10+rem;
   no=no/10;
   }
  return rev;
  }

Leave a Reply

Your email address will not be published. Required fields are marked *