Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. DYNAMICZNA TABLICA 2D
  2.  
  3. int main() {
  4. srand(time(NULL));
  5. int n, w;
  6. cout << "Podaj liczbe wierszy:";
  7. cin >> n;
  8. cout << "Podaj liczbe kolumn:";
  9. cin >> w;
  10.  
  11. int* *tab = new int *[n];
  12.  
  13.  
  14. for (int i = 0; i < n; i++)
  15. tab[i] = new int[w] {};
  16.  
  17.  
  18. for (int i = 0; i < n; i++)
  19. for(int j=0;j<w;j++){
  20. cout << "Podaj element [" << i << "]["<<j<<"]: ";
  21. cin >> tab[i][j];
  22. }
  23.  
  24. int** tab2 = new int* [w];
  25.  
  26.  
  27. for (int i = 0; i < w; i++)
  28. tab2[i] = new int[n] {};
  29.  
  30.  
  31. for (int i = 0; i < w; i++)
  32. for (int j = 0; j < n; j++) {
  33. tab2[i][j] = tab[j][i];
  34. }
  35. cout << endl;
  36.  
  37. for (int i = 0; i < n; i++) {
  38. for (int j = 0; j < w; j++)
  39. cout << tab[i][j]<<" ";
  40. cout << endl;
  41. }
  42. cout << endl;
  43.  
  44. for (int i = 0; i < w; i++) {
  45. for (int j = 0; j < n; j++)
  46. cout << tab2[i][j] << " ";
  47. cout << endl;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement