Advertisement
Bitroy

Fibanachi

Jan 17th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int a;
  4. int sum = 0;
  5. int mas[100];
  6.  
  7.  
  8. void massive (int i)
  9. {
  10. if (i <= a)
  11. {
  12. mas[0] = 0;
  13. mas[1] = 1;
  14. mas[i] = mas[i-1] + mas[i-2];
  15. massive(i+1);
  16. }
  17. }
  18.  
  19. void suma (int i)
  20. {
  21. mas[0] = 0;
  22. mas[1] = 1;
  23. if (i <= a)
  24. {
  25. sum += (mas[i-1] + mas[i-2]);
  26. suma(i+1);
  27. }
  28. }
  29. int main()
  30. {
  31. scanf ("%d", &a);
  32. mas[0] = 0;
  33. mas[1] = 1;
  34. sum = mas[0] + mas[1];
  35. massive(3);
  36. suma(3);
  37. if (a == 0)
  38. {
  39. printf("%d", a);
  40. }
  41. else
  42. {
  43. printf("%d", sum);
  44. }
  45. return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement