ChameL1oN

Лаба5_Задача1(Вар.16)

Dec 14th, 2014
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. #include <iostream>
  2. #include <locale>
  3. #include <fstream>
  4. #include <stdlib.h>
  5. #include <time.h>
  6.  
  7. using namespace std;
  8.  
  9. // Найти количество чисел Фибоначчи в массиве.
  10. int* form_massive(int count){
  11. int* massive = new int[count];
  12. int a = 0;
  13. time_t t;
  14. srand((unsigned)time(&t));
  15. while (a < count){
  16. massive[a] = rand()%50;
  17. cout << "massive [" << a << "] = " << massive[a] << endl;
  18. a++;
  19. }
  20. return massive;
  21. }
  22. int fibo(int n){
  23. if ((n == 1) || (n == 2)) return 1;
  24. return (fibo(n - 1) + fibo(n - 2));
  25. }
  26. void init_massive(int massive[], int &count){
  27. int n, num,i=0,j=0;
  28. n = 3;
  29. while (j < count){
  30. num = massive[j];
  31. while (n <= 100){
  32. if (fibo(n) == massive[j]){
  33. i++;
  34. }
  35. if (fibo(n) > massive[j]) break;
  36. n++;
  37. }
  38. n = 3;
  39. j++;
  40. }
  41. cout << "Чисел Фибоначчи : " << i << endl;;
  42. }
  43.  
  44. void main(){
  45. int count, k;
  46. setlocale(LC_ALL, "rus");
  47. cout << "Введите кол-во элементов в массиве ";
  48. cin >> count;
  49. int* mas = form_massive(count);
  50. init_massive(mas, count);
  51.  
  52.  
  53. }
Advertisement
Add Comment
Please, Sign In to add comment