Algorithms_in_C  1.0.0
Set of algorithms implemented in C.
power_recursion.c File Reference

Program to calculate exponentiation using recursion algorithm. More...

#include <assert.h>
Include dependency graph for power_recursion.c:

Functions

long power (int a, int b)
 Returns the value of the first argument raised to the power of the second argument using recursion. More...
 
static void test ()
 Test function. More...
 
int main ()
 Driver Code. More...
 

Detailed Description

Program to calculate exponentiation using recursion algorithm.

Author
Du Yuanchao

Function Documentation

◆ main()

int main ( void  )

Driver Code.

Returns
0 on exit
37 {
38  test();
39  return 0;
40 }
Here is the call graph for this function:

◆ power()

long power ( int  a,
int  b 
)

Returns the value of the first argument raised to the power of the second argument using recursion.

Parameters
athe base.
bthe exponent.
Returns
the value
a
b
.
18 { return b == 0 ? 1 : a * power(a, b - 1); }

◆ test()

static void test ( void  )
static

Test function.

Returns
void
25 {
26  assert(power(0, 2) == 0);
27  assert(power(2, 3) == 8);
28  assert(power(2, 10) == 1024);
29  assert(power(3, 3) == 27);
30 }
Here is the call graph for this function:
test
static void test()
Test function.
Definition: power_recursion.c:24
power
long power(int a, int b)
Returns the value of the first argument raised to the power of the second argument using recursion.
Definition: power_recursion.c:18