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

Program to calculate exponentiation More...

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

Functions

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

Detailed Description

Program to calculate exponentiation

Author
Du Yuanchao

Function Documentation

◆ main()

int main ( void  )

Driver Code.

Returns
0 on exit
44 {
45  test();
46  return 0;
47 }
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.

Parameters
athe base.
bthe exponent.
Returns
the value
a
b
.
18 {
19  long result = 1;
20  for (int i = 1; i <= b; ++i)
21  {
22  result *= a;
23  }
24  return result;
25 }

◆ test()

static void test ( void  )
static

Test function.

Returns
void
32 {
33  assert(power(0, 2) == 0);
34  assert(power(2, 3) == 8);
35  assert(power(2, 10) == 1024);
36  assert(power(3, 3) == 27);
37 }
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.
Definition: power.c:17
test
static void test()
Test function.
Definition: power.c:31