Advertisement
Kimossab

[AP]Ficha 10

Dec 12th, 2015
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.78 KB | None | 0 0
  1. #include <stdio.h>
  2. /*
  3.     NOTA: pot_rec feito no exercicio 3
  4. */
  5.  
  6. // - 4
  7. float som(int n, float r,float fact=1,float exp=1,int i=1)
  8. {
  9.     fact*=i;
  10.     exp*=r;
  11.     if(n==i)
  12.         return exp/fact;
  13.  
  14.     return exp/fact + som(n,r,fact,exp,i+1);//++i
  15. }
  16.  
  17. /*float som2(float r, int i)
  18. {
  19.     if(i==1)
  20.         return r;
  21.     return pot_rec(i,r)/fat_rec(i) + som2(r,i-1);
  22. }*/
  23.  
  24. // - 5
  25. /*float soma(int n, float fat=1, i=1)
  26. {
  27.     fat*=i;
  28.     if(i==n)
  29.         return pot_rec(i,fat);
  30.     return pot_rec(i,fat) + soma(n,fat,i+1);
  31. }*/
  32. float soma2(int i, float fat=1)
  33. {
  34.     fat*=i;
  35.     if(i==1)
  36.         return 1;
  37.     return pot_rec(i,fat) + soma(n,fat,i-1);
  38. }
  39. void main ()
  40. {
  41.     //4
  42.     float r;
  43.     int n;
  44.     printf("Introduza o valor de N");
  45.     scanf("%d",&n);
  46.     printf("introduza o r: ");
  47.     scanf("%f",&r);
  48.     printf("Resposta: %f", som(n,r));
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement