idastan97

CSCI151 L18 P1 A

Sep 29th, 2016
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.23 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>0) return power(x, n-1)*x;
  6.     else return power(x, n+1)/x;
  7. }
  8.  
  9. int main(){
  10.     double x=2.0;
  11.     int n=-3;
  12.     printf("%f", power(x, n));
  13.     return 0;
  14. }
Advertisement
Add Comment
Please, Sign In to add comment