Tuesday, March 27, 2012

Evaluating a^x where 'a' is the base and 'x' is the exponent , using recursion


#include
int exponent(int, int);
int main()
{

int a,b;
printf("\n Enter the base and exponent: ");
  scanf("%d %d",&a,&b);

printf("\n The exponent of %d over %d is %d",a,b,exponent(a,b));

return 0;
}
int exponent(int k,int l)
 {
int x;
if(l<=0)
 return 1;
  x=exponent(k,(l-1));

return (x*k);

 }

[/THis is the program that I wrote just before mid-sem exam]