Advertisement
Guest User

nx1

a guest
Jan 30th, 2016
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.28 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. void wczytaj_tab(int tab[], int n)
  6. {
  7.     for(int i=0;i<n;++i)
  8.     {
  9.         //tab[i]=rand()%10;
  10.         cout << "Podaj " << i+1 <<" element: ";cin >> tab[i];
  11.     }
  12. }
  13. void wypisz_tab(int tab[], int n)
  14. {
  15.     for(int i=0;i<n;++i)
  16.     {
  17.         cout << tab[i] << "\t";
  18.     }
  19.     cout << endl;
  20. }
  21. int maks(int tab[], int n)
  22. {
  23.     int m=tab[0];
  24.     for(int i=0;i<n;++i)
  25.     {
  26.         if(tab[i]>m) m=tab[i];
  27.     }
  28.     return m;
  29. }
  30. int main()
  31. {
  32. int n;
  33. cout << "Podaj ilosc elemtentow: ";cin >> n; cout << endl;
  34. int tab1[n];
  35. int tab2[n];
  36. int tab3[n];
  37. wczytaj_tab(tab1,n);
  38. for(int i=0;i<n;++i)
  39. {
  40.     if(i==0)
  41.     {
  42.         tab2[i]=tab1[i];
  43.         tab3[i]=i;
  44.     }
  45.     else if(i==1)
  46.     {
  47.         tab2[i]=tab1[i];
  48.         tab3[i]=tab2[i-1];
  49.     }
  50.     else if(i>1)
  51.     {
  52.         tab2[i]=tab1[i]+tab3[i-1];
  53.         if(tab2[i-1]>tab3[i-1])
  54.         {
  55.             tab3[i]=tab2[i-1];
  56.         }
  57.         else
  58.         {
  59.             tab3[i]=tab3[i-1];
  60.         }
  61.     }
  62. }
  63. cout << "TABLICA PODANA: " << endl;
  64. wypisz_tab(tab1,n);
  65. cout << "TABLICA DRUGA:" << endl;
  66. wypisz_tab(tab2,n);
  67. cout << "TABLICA TRZECIA:" << endl;
  68. wypisz_tab(tab3,n);
  69. cout << "Najwieksza suma: " << endl;
  70. cout << maks(tab2,n) << endl;
  71. return 0;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement