Advertisement
Biboran

Функции

Dec 22nd, 2014
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.88 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <locale>
  4. #include <iomanip>
  5. #include <cmath>
  6. using namespace std;
  7. void print(int, int *);
  8. bool fib(int, int *);
  9. void sort(int, int *);
  10. void fib2(int m, int *a, int &check);
  11. int m, n;
  12. int main()
  13. {
  14.     const int N = 100;
  15.     const int M = 100;
  16.     int a[N][M];
  17.     setlocale(LC_ALL, "rus");
  18.     cout << "Введите количество десятков" << endl;
  19.     cin >> n;
  20.     do
  21.     {
  22.         cout << "Введите количество элементов строки" << endl;
  23.         cin >> m;
  24.     } while (m<2);
  25.     for (int i = 0; i < n; i++)
  26.         for (int j = 0; j < m; j++)
  27.         {
  28.         cout << "a[" << i << "]" << "[" << j << "]=";
  29.         cin >> a[i][j];
  30.         }
  31.     system("cls");
  32.  
  33.     cout << "\n-----------------------------------------------------------";
  34.     cout.unsetf(ios::left);
  35.     for (int i = 0; i < n; i++)
  36.     {
  37.         int check=0;
  38.         print(m, a[i]);
  39.         fib2(m, a[i],  check);
  40.         if (check == 0)
  41.             cout << "\t Является рядом Фибоначчи ";
  42.     }
  43.     cout << "\n-----------------------------------------------------------\n";
  44.     system("pause");
  45.     return 0;
  46. }
  47.  
  48. void print(int m, int *a)
  49. {
  50.     cout << "\n";
  51.  
  52.     for (int j = 0; j < m; j++)
  53.         cout << setw(5) << a[j];
  54. }
  55.  
  56. void sort(int m, int *a)
  57. {
  58.     for (int j = 0, value; j < m - 1; j++)     //столбец
  59.         for (int k = j; k < m; k++)    //сортировка
  60.             if (a[j] > a[k])
  61.             {
  62.         value = a[j];
  63.         a[j] = a[k];
  64.         a[k] = value;
  65.             }
  66.  
  67. }
  68.  
  69. bool fib(int m, int *a)
  70. {
  71.     sort(m, a);
  72.     if ((a[0] == 0) && (a[1] == 1))
  73.     {
  74.         for (int j = 2; j < m; j++)
  75.         {
  76.             if ((a[j - 1] + a[j - 2]) != a[j])
  77.                 return false;
  78.         }
  79.     }
  80.     else
  81.         return false;
  82.     return true;
  83.  
  84. }
  85.  
  86. void fib2(int m, int *a, int &check)
  87. {
  88.     sort(m, a);
  89.     if ((a[0] == 0) && (a[1] == 1))
  90.     {
  91.         for (int j = 2; j < m; j++)
  92.         {
  93.             if ((a[j - 1] + a[j - 2]) != a[j])
  94.                 check = 0;
  95.         }
  96.     }
  97.     else
  98.         check = 0;
  99.     check = 1;
  100.  
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement