[ create a new paste ] login | about

Link: http://codepad.org/4LEP30ae    [ raw code | output | fork ]

C, pasted on Jan 20:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <stdio.h>
 
double go_pow( double base, int exp )
{
   size_t i;
   double res = 1;
 
   if ( exp < 0 )
      res = go_pow ( 1 / base , -1 * exp );
   else
   {
      for ( i = 0 ; i < (size_t) exp ; ++i )
         res *= base;
   }
   return res;
}
 
int main(void){
        printf("%f\n", go_pow(2.0, -2));
        return 0;
}


Output:
1
0.250000


Create a new paste based on this one


Comments: