Advertisement
Guest User

Untitled

a guest
Jan 16th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 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. int sumatab(int b[], int j)
  38. {
  39. int w = 0;
  40. for (int i = 0; i < j; i++)
  41. w = w + b[i];
  42. return w;
  43. }
  44.  
  45. int sprawdz(int n1, int tab[])
  46. {
  47. int l=0;
  48. int p = sumatab(tab, n1);
  49. // cout << l << " " << p << endl;
  50. for (int i = 0; i < n1; i++)
  51. {
  52.  
  53. // cout << i;
  54. l = tab[i] + l;
  55. // cout << l << "l" << endl;
  56. p = p - tab[i];
  57. // cout << p << "p" << endl;
  58.  
  59. if (l < p)
  60. {
  61. return i;
  62.  
  63. }
  64.  
  65. }
  66. }
  67.  
  68.  
  69. int main() {
  70.  
  71. int a[N];
  72. int n, wybor; //n - dlugość ciągu liczb
  73. cout << endl;
  74. cout << "MENU GLOWNE" << endl;
  75. cout << "1.Liczby wybierane przez uzytkownika" << endl;
  76. cout << "2.Liczby losowo wybierane" << endl;
  77. cout << "3.Wyscie." << endl;;
  78.  
  79. cout << "Wybierz opcje: ";
  80. cin >> wybor;
  81. cout << "podaj liczbe elementow: ";
  82. cin >> n;
  83. switch (wybor) {
  84. case 2: Losowy(a, n); break;
  85. case 1: Podaj(a, n); break;
  86. default: exit(0);
  87. }
  88. if (sprawdz(n, a) == n - 1)
  89. cout << "nie istnieje takie k by P>L w tym ciagu" << endl;
  90. else
  91. cout << endl <<"k= "<< sprawdz(n, a);
  92.  
  93. cout << "\n\n\n"; system("pause");
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement