idastan97

CSCI151 L18 P1 B

Oct 2nd, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.28 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. double power(double x, int n) {
  4.     if (n==0) return 1;
  5.     if (n==1) return x;
  6.     if (n==-1) return 1/x;
  7.     return power(x, n/2)*power(x, n/2)*power(x, n%2);
  8. }
  9.  
  10. int main(){
  11.     double x=2.0;
  12.     int n=5;
  13.     printf("%f", power(x, n));
  14.     return 0;
  15. }
Advertisement
Add Comment
Please, Sign In to add comment