Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<cmath>
- #include<string>
- #include <algorithm>
- #include <ctime>
- using namespace std;
- const int N = 10000;
- void Podaj(int tab[], int n1)
- {
- int l;
- cout << "Podaj liczby ciagu:";
- for (int i = 0; i < n1; i++)
- {
- cin >> l;
- tab[i] = l;
- //cout << tab[i] << " ";
- }
- }
- void Losowy(int tab[], int n1)
- {
- srand(unsigned(time(0)));
- int l1, l2;
- cout << "Podaj przedzial liczb w ciagu:" << endl;
- cin >> l1 >> l2; cout << endl;
- for (int i = 0; i < n1; i++)
- {
- tab[i] = l1 + rand() % (l2 - l1 + 1);
- cout << tab[i] << " ";
- }
- }
- int sumatab(int b[], int j)
- {
- int w = 0;
- for (int i = 0; i < j; i++)
- w = w + b[i];
- return w;
- }
- int sprawdz(int n1, int tab[])
- {
- int l=0;
- int p = sumatab(tab, n1);
- // cout << l << " " << p << endl;
- for (int i = 0; i < n1; i++)
- {
- // cout << i;
- l = tab[i] + l;
- // cout << l << "l" << endl;
- p = p - tab[i];
- // cout << p << "p" << endl;
- if (l < p)
- {
- return i;
- }
- }
- }
- int main() {
- int a[N];
- int n, wybor; //n - dlugość ciągu liczb
- cout << endl;
- cout << "MENU GLOWNE" << endl;
- cout << "1.Liczby wybierane przez uzytkownika" << endl;
- cout << "2.Liczby losowo wybierane" << endl;
- cout << "3.Wyscie." << endl;;
- cout << "Wybierz opcje: ";
- cin >> wybor;
- cout << "podaj liczbe elementow: ";
- cin >> n;
- switch (wybor) {
- case 2: Losowy(a, n); break;
- case 1: Podaj(a, n); break;
- default: exit(0);
- }
- if (sprawdz(n, a) == n - 1)
- cout << "nie istnieje takie k by P>L w tym ciagu" << endl;
- else
- cout << endl <<"k= "<< sprawdz(n, a);
- cout << "\n\n\n"; system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement