C Programming
Computer Programming

C Program using function to Calculate the power of a number using recursion



Write a Program in C using function to Calculate the power of a number using recursion

\* C Program using function to Calculate the power of a number using recursion *\

# include < stdio.h >
# include < conio.h >
int   power( int n1, int n2 ) ;

int   main( )
{

int base, powerRaised, result ;
printf("\n Enter base number: ") ;
scanf("%d", &base) ;
printf(" Enter power number( positive integer ): ") ;
scanf("%d", &powerRaised) ;
result = power( base, powerRaised ) ;
printf(" %d^%d = %d", base, powerRaised, result ) ;
return 0 ;

}

int   power( int base, int powerRaised ) ;

{

if ( powerRaised != 0 )
      return ( base*power ( base, powerRaised - 1 ) ) ;
else
      return 1 ;

}

Output of Program :

Output of C Program using function to Calculate the power of a number using recursion