Advertisement
caduweb

Potência Recursivamente

Dec 15th, 2018
408
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.29 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. double func(double x, int n)
  4. {
  5.  
  6.   if (n < 0)
  7.   {
  8.     return (1/x) * func(x, ++n);
  9.   }
  10.  
  11.   if (n > 0)
  12.   {
  13.      return x * func(x, --n);
  14.   }
  15.  
  16.   return 1;
  17. }
  18.  
  19.  
  20. int main ()
  21. {
  22.   printf("%.0lf\n", func(10, 2));
  23.   printf("%lf\n", func(10, -2));
  24.  
  25.   return 0;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement