### Introduction

In this i have made use of recursion to calculate x to the power n

Code: Cpp

#include <stdio.h>

main()

{

float x;

int n;

printf("\n enter values of x an n");

printf("\n %.4f to the power of % d is %.4f",x,n,power(x,n));

}

Code: Cpp

float power(float x, int n)

{

if (x==0)

{

return 0;

}

else if(n==0)

{

return 1;

}

else if (n>0)

{

return( x* power(x,n-1));

}

else

{

return ((1/x)*power(x,n+1));

}

}

shabbir
like this