Program to find Recursive function power(x,y) to find x^y


          # include <iostream.h>
          # include<conio.h>
           int power ( int x, int y);
        void main( )
        {
             int x, y  ;
             cout<< "\n Enter value of x & y : ";
             cin>>x>>y;
             cout<<"\n"<<x<<" ^ "<<y<<" = "<< power(x,y);
            }
                int power (int x, int y)          // Recursive power function
               {
                 if (y ==1)
                        return x;
                 else
          return(x * power(x,y-1));
          }

0 comments:

Post a Comment

 
 
 
 


Copyright © 2012 http://codeprecisely.blogspot.com. All rights reserved |Term of Use and Policies|