Our own power function : Power « Math « C / ANSI-C






Our own power function

  
#include <stdio.h>

int power(void);

int m, e;

int main(void)
{
  m = 2;
  e = 3;

  printf("%d raised to the %d power = %d", m, e, power());

  return 0;
}

int power(void)
{
  int temp, temp2;

  temp = 1;
  temp2 = e;
  for( ; temp2> 0; temp2--) 
      temp = temp * m;

  return temp;
}


           
       








Related examples in the same category

1.How to use powHow to use pow
2.Calculate numeric power: how to use powCalculate numeric power: how to use pow