Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- void wczytaj_tab(int tab[], int n)
- {
- for(int i=0;i<n;++i)
- {
- //tab[i]=rand()%10;
- cout << "Podaj " << i+1 <<" element: ";cin >> tab[i];
- }
- }
- void wypisz_tab(int tab[], int n)
- {
- for(int i=0;i<n;++i)
- {
- cout << tab[i] << "\t";
- }
- cout << endl;
- }
- int maks(int tab[], int n)
- {
- int m=tab[0];
- for(int i=0;i<n;++i)
- {
- if(tab[i]>m) m=tab[i];
- }
- return m;
- }
- int main()
- {
- int n;
- cout << "Podaj ilosc elemtentow: ";cin >> n; cout << endl;
- int tab1[n];
- int tab2[n];
- int tab3[n];
- wczytaj_tab(tab1,n);
- for(int i=0;i<n;++i)
- {
- if(i==0)
- {
- tab2[i]=tab1[i];
- tab3[i]=i;
- }
- else if(i==1)
- {
- tab2[i]=tab1[i];
- tab3[i]=tab2[i-1];
- }
- else if(i>1)
- {
- tab2[i]=tab1[i]+tab3[i-1];
- if(tab2[i-1]>tab3[i-1])
- {
- tab3[i]=tab2[i-1];
- }
- else
- {
- tab3[i]=tab3[i-1];
- }
- }
- }
- cout << "TABLICA PODANA: " << endl;
- wypisz_tab(tab1,n);
- cout << "TABLICA DRUGA:" << endl;
- wypisz_tab(tab2,n);
- cout << "TABLICA TRZECIA:" << endl;
- wypisz_tab(tab3,n);
- cout << "Najwieksza suma: " << endl;
- cout << maks(tab2,n) << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement