To find the power of a number using recursion

#include <iostream.h>
#include <conio.h>

int main ()
{ 
  clrscr (); 
  int power (int a, int b); 
  int x,y,r; 
  cin >> x >> y; 
  r = power(x,y); 
  cout<< "\nresult =" << r <<"\n"; 
  return 0;
}

int power (int a, int b)
{ 
  if(b == 0)  
  return (1); 
  else   
  return (a * power (a, b-1) );
}

About Shajahan

Engineer πŸ“š Introvert 🚢🏻 Sapiosexual πŸ€” Movie buff and TV shows addict πŸ–₯ Android enthusiast 😎 Food lover πŸ₯˜ Little obsessive πŸ˜‡

Posted on May 18, 2011, in Comp. Sc and tagged , . Bookmark the permalink. Leave a comment.

Leave a comment