Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <locale>
- #include <iomanip>
- #include <cmath>
- using namespace std;
- void print(int, int *);
- bool fib(int, int *);
- void sort(int, int *);
- void fib2(int m, int *a, int &check);
- int m, n;
- int main()
- {
- const int N = 100;
- const int M = 100;
- int a[N][M];
- setlocale(LC_ALL, "rus");
- cout << "Введите количество десятков" << endl;
- cin >> n;
- do
- {
- cout << "Введите количество элементов строки" << endl;
- cin >> m;
- } while (m<2);
- for (int i = 0; i < n; i++)
- for (int j = 0; j < m; j++)
- {
- cout << "a[" << i << "]" << "[" << j << "]=";
- cin >> a[i][j];
- }
- system("cls");
- cout << "\n-----------------------------------------------------------";
- cout.unsetf(ios::left);
- for (int i = 0; i < n; i++)
- {
- int check=0;
- print(m, a[i]);
- fib2(m, a[i], check);
- if (check == 0)
- cout << "\t Является рядом Фибоначчи ";
- }
- cout << "\n-----------------------------------------------------------\n";
- system("pause");
- return 0;
- }
- void print(int m, int *a)
- {
- cout << "\n";
- for (int j = 0; j < m; j++)
- cout << setw(5) << a[j];
- }
- void sort(int m, int *a)
- {
- for (int j = 0, value; j < m - 1; j++) //столбец
- for (int k = j; k < m; k++) //сортировка
- if (a[j] > a[k])
- {
- value = a[j];
- a[j] = a[k];
- a[k] = value;
- }
- }
- bool fib(int m, int *a)
- {
- sort(m, a);
- if ((a[0] == 0) && (a[1] == 1))
- {
- for (int j = 2; j < m; j++)
- {
- if ((a[j - 1] + a[j - 2]) != a[j])
- return false;
- }
- }
- else
- return false;
- return true;
- }
- void fib2(int m, int *a, int &check)
- {
- sort(m, a);
- if ((a[0] == 0) && (a[1] == 1))
- {
- for (int j = 2; j < m; j++)
- {
- if ((a[j - 1] + a[j - 2]) != a[j])
- check = 0;
- }
- }
- else
- check = 0;
- check = 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement