Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <ctime>
- #include <cstdlib>
- #include <iomanip>
- using namespace std;
- int main()
- {
- int x, y;
- do
- {
- cout << "Podaj liczbe wierszy: ";
- cin >> x;
- } while (x < 1);
- do
- {
- cout << "Podaj liczbe kolumn: ";
- cin >> y;
- } while (y < 1);
- int tab[x][y];
- srand((unsigned)time(NULL));
- for(int i = 0; i < x; i++)
- {
- for(int j = 0; j < y; j++)
- {
- tab[i][j] = rand()%10+1;
- }
- }
- for(int i = 0; i < x; i++)
- {
- for(int j = 0; j < y; j++)
- {
- cout << setw(4);
- cout << tab[i][j];
- }
- cout<<endl;
- }
- cout << endl;
- int suma = tab[0][0];
- cout << tab[0][0] << " ";
- int i = 0,j = 0;
- while ((i != x-1) || (j != y-1))
- {
- if (i + 1 > x - 1)
- {
- cout << tab[i][++j] << " ";
- suma=suma+tab[i][j];
- }
- else
- if (j + 1 > y - 1)
- {
- cout << tab[++i][j] << " ";
- suma=suma+tab[i][j];
- }
- else
- if(tab[i][j+1]>tab[i+1][j])
- {
- cout << tab[i][++j] << " ";
- suma=suma+tab[i][j];
- }
- else
- {
- cout << tab[++i][j] << " ";
- suma=suma+tab[i][j];
- }
- }
- cout<<endl;
- cout<<suma;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement