Advertisement
it4l0

serie

Dec 3rd, 2019
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.01 KB | None | 0 0
  1. #include <stdio.h>
  2. int eprimo(int x)
  3. {
  4.     int y = 2;
  5.     while (x > y)
  6.     {
  7.         if (x % y == 0)
  8.         {
  9.             return 0;
  10.         }
  11.         y++;
  12.     }
  13.     return x;
  14. }
  15. int fatorial(int x)
  16. {
  17.     int resultado;
  18.     if (x == 1)
  19.     {
  20.         return 1;
  21.     }
  22.     else{
  23.         resultado = x * fatorial(x - 1);
  24.     }
  25.     return resultado;
  26. }
  27. int proxprimo(int z)
  28. {
  29.     if(eprimo(z) == 0)
  30.     {
  31.         proxprimo(z + 1);
  32.     }
  33.     else if(eprimo(z) == 1)
  34.     {
  35.         return z;
  36.     }
  37. }
  38. int main()
  39. {
  40.     int termo = 1, n = 0, prox1 = 0;
  41.     double resposta = 0.0, prox = 0, fat = 0;
  42.     scanf("%d", &n);
  43.     for( ; termo <= n; termo++)
  44.     {
  45.         if (termo == 1)
  46.         {
  47.             resposta += 1.00;
  48.             printf("1!/1");
  49.         } else{
  50.             fat = fatorial(termo); prox = proxprimo(termo); prox1 = prox;
  51.             resposta += fat / prox;
  52.             printf(" + %d!/%d", termo, prox1);
  53.         }
  54.     }
  55.     printf("\n%.2lf", resposta);
  56.     return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement