SHARE
TWEET

exercicio2 lsita entrega

bombardelli May 22nd, 2019 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. float potencia(float base, int expoente){
  5.     int i;
  6.     if(base == 0){
  7.         return 0;
  8.     }
  9.     if(expoente == 0){
  10.         return 1;
  11.     }
  12.     if(expoente > 0){
  13.         return base * potencia(base , expoente - 1);
  14.     }
  15.     if(expoente < 0){
  16.         expoente *= -1;
  17.         return 1 / (base* potencia(base , expoente - 1));
  18.     }
  19.  
  20. }
  21.  
  22.  
  23. int main()
  24. {
  25.     float resul, b;
  26.     int e;
  27.     printf("Digite o valor da base e do expoente:");
  28.     scanf("%f %d", &b, &e);
  29.  
  30.     resul = potencia(b, e);
  31.  
  32.     printf("resultado: %.2f", resul);
  33.     printf("\n\n");
  34.     printf("resultado chamando direto a funcao: %f", potencia(b, e));
  35.  
  36.     return 0;
  37. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top