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) ); }
Posted on May 18, 2011, in Comp. Sc and tagged C++, recursion. Bookmark the permalink. Leave a comment.
Leave a comment
Comments 0