G2A Many GEOs
SHARE
TWEET

Untitled

a guest Apr 6th, 2020 193 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int fibonacci(int i)
  5. { if (i == 1)
  6.   { return 0; }
  7.  
  8.  else if (i > 1)
  9. { int a = 0;
  10.   int b = 1;
  11.  
  12. for (int j = 2; j < i; j++)
  13. { int c = a + b;
  14.       a = b;
  15.       b = c; }
  16.  
  17. return b; } }
  18.  
  19. int main()
  20. {   int j, i = 1, d, a;
  21.  
  22.     printf("Digite um numero, para verificar se ele pertence a essa sequencia: ");
  23.     scanf("%d", &d);
  24.  
  25.     for(j = 0; ;j++)
  26.     { a = fibonacci(j);
  27.  
  28.       if (d == a)
  29.       { printf("\npertence.\n");
  30.         break; }
  31.  
  32.       else
  33.       { printf("\nnao pertence.\n");
  34.         break; } }
  35.  
  36.     return 0; }
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
Top