Advertisement
Guest User

Untitled

a guest
Jan 16th, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. #include<iostream>
  2. #include<cmath>
  3. #include<string>
  4. #include <algorithm>
  5. #include <ctime>
  6.  
  7. using namespace std;
  8. const int N = 10000;
  9.  
  10.  
  11. void Podaj(int tab[], int n1)
  12. {
  13. int l;
  14. cout << "Podaj liczby ciagu:";
  15.  
  16. for (int i = 0; i < n1; i++)
  17. {
  18. cin >> l;
  19. tab[i] = l;
  20. cout << tab[i] << " ";
  21. }
  22. }
  23.  
  24. void Losowy(int tab[], int n1)
  25. {
  26. srand(unsigned(time(0)));
  27. int l1, l2;
  28. cout << "Podaj przedzial liczb w ciagu:" << endl;
  29. cin >> l1 >> l2; cout << endl;
  30. for (int i = 0; i < n1; i++)
  31. {
  32. tab[i] = l1 + rand() % (l2 - l1 + 1);
  33. cout << tab[i] << " ";
  34. }
  35. }
  36.  
  37. string sprawdz(int n1, int tab[])
  38. {
  39. int wynik=0;
  40. string k = "nie";
  41. for (int i = 1; i < n1; i++)
  42. {
  43. wynik =wynik + tab[i-1];
  44. if (tab[i] % abs(wynik) == 0) // abs - wartosc bezwgledna liczby
  45. {
  46. k = "tak";
  47. goto koniec;
  48. }
  49. }
  50. koniec:
  51. return k;
  52. }
  53.  
  54. int main() {
  55.  
  56. int a[N];
  57. int n; //n - dlugość ciągu liczb
  58. cout << "Wpisz n - długość ciagu liczb" << endl;
  59. cin >> n; //n podane przez użytkownika nie może być większe od N
  60. cout << "Wybierz sposób wpisania ciagu liczb: 0 dla losowych liczb ciagu, 1 dla wlasnorecznego wstawiania." << endl;
  61. int wybor;
  62. cin >> wybor;
  63. switch (wybor) {
  64. case 0: Losowy(a, n); break;
  65. case 1: Podaj(a, n); break;
  66. }
  67. cout <<endl<<sprawdz(n, a);
  68.  
  69. cout << "\n\n\n"; system("pause");
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement