Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <locale>
- #include <fstream>
- #include <stdlib.h>
- #include <time.h>
- using namespace std;
- // Найти количество чисел Фибоначчи в массиве.
- int* form_massive(int count){
- int* massive = new int[count];
- int a = 0;
- time_t t;
- srand((unsigned)time(&t));
- while (a < count){
- massive[a] = rand()%50;
- cout << "massive [" << a << "] = " << massive[a] << endl;
- a++;
- }
- return massive;
- }
- int fibo(int n){
- if ((n == 1) || (n == 2)) return 1;
- return (fibo(n - 1) + fibo(n - 2));
- }
- void init_massive(int massive[], int &count){
- int n, num,i=0,j=0;
- n = 3;
- while (j < count){
- num = massive[j];
- while (n <= 100){
- if (fibo(n) == massive[j]){
- i++;
- }
- if (fibo(n) > massive[j]) break;
- n++;
- }
- n = 3;
- j++;
- }
- cout << "Чисел Фибоначчи : " << i << endl;;
- }
- void main(){
- int count, k;
- setlocale(LC_ALL, "rus");
- cout << "Введите кол-во элементов в массиве ";
- cin >> count;
- int* mas = form_massive(count);
- init_massive(mas, count);
- }
Advertisement
Add Comment
Please, Sign In to add comment