Advertisement
Guest User

Untitled

a guest
Mar 24th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. #include <iostream>
  2. #include <ctime>
  3. #include <cstdlib>
  4. #include <iomanip>
  5.  
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10. int x, y;
  11. do
  12. {
  13. cout << "Podaj liczbe wierszy: ";
  14. cin >> x;
  15. } while (x < 1);
  16. do
  17. {
  18. cout << "Podaj liczbe kolumn: ";
  19. cin >> y;
  20. } while (y < 1);
  21. int tab[x][y];
  22.  
  23. srand((unsigned)time(NULL));
  24. for(int i = 0; i < x; i++)
  25. {
  26. for(int j = 0; j < y; j++)
  27. {
  28. tab[i][j] = rand()%10+1;
  29. }
  30. }
  31. for(int i = 0; i < x; i++)
  32. {
  33. for(int j = 0; j < y; j++)
  34. {
  35. cout << setw(4);
  36. cout << tab[i][j];
  37. }
  38. cout<<endl;
  39. }
  40. cout << endl;
  41. int suma = tab[0][0];
  42. cout << tab[0][0] << " ";
  43. int i = 0,j = 0;
  44.  
  45. while ((i != x-1) || (j != y-1))
  46. {
  47. if (i + 1 > x - 1)
  48. {
  49. cout << tab[i][++j] << " ";
  50. suma=suma+tab[i][j];
  51. }
  52. else
  53. if (j + 1 > y - 1)
  54. {
  55. cout << tab[++i][j] << " ";
  56. suma=suma+tab[i][j];
  57. }
  58. else
  59. if(tab[i][j+1]>tab[i+1][j])
  60. {
  61. cout << tab[i][++j] << " ";
  62. suma=suma+tab[i][j];
  63. }
  64. else
  65. {
  66. cout << tab[++i][j] << " ";
  67. suma=suma+tab[i][j];
  68. }
  69. }
  70. cout<<endl;
  71. cout<<suma;
  72.  
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement