Advertisement
MeehoweCK

Untitled

Nov 30th, 2018
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.70 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <ctime>
  4.  
  5. using namespace std;
  6.  
  7. /*A20. Napisać funkcję
  8. bool a(int* t, int r)
  9. która zwraca true wtedy i tylko wtedy, gdy w tablicy t o rozmiarze r znajduje się ciąg
  10. arytmetyczny*/
  11.  
  12. bool a(int* t, int r)
  13. {
  14.     if(r < 2)
  15.         return false;
  16.     int roznica = t[1] - t[0];
  17.  
  18.     for(int i = 2; i < r; ++i)
  19.         if((t[i] - t[i-1]) != roznica)
  20.             return false;
  21.     return true;
  22. }
  23.  
  24. int main()
  25. {
  26.     srand(static_cast<unsigned>(time(nullptr)));
  27.     int tablica[3];
  28.     for(int i = 0; i < 3; ++i)
  29.     {
  30.         tablica[i] = rand()%5;
  31.         cout << tablica[i] << " ";
  32.     }
  33.  
  34.     cout << endl << a(tablica, 3);
  35.  
  36.     return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement