Advertisement
PatrickSwayze

zadanie 11 wsk

Dec 20th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.40 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3. #include<ctime>
  4. #include<cstdlib>
  5. #include<windows.h>
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10. int x,y,z;
  11. cout<<"Rozmiary tablicy: ";
  12. cin>>x>>y>>z;
  13.  
  14. int ***tab;
  15. tab=new int **[x];
  16.  
  17. for (int i=0; i<x; i++) //deklaracja tablicy ***
  18. {
  19. tab[i]=new int *[y];
  20. for (int j=0; j<y; j++)
  21. {
  22. tab[i][j]=new int [z];
  23. }
  24. }
  25. srand(time(NULL));
  26. for (int i=0; i<x; i++) //wypelnienie tablicy ***
  27. {
  28. for (int j=0; j<y; j++)
  29. {
  30. for(int t=0; t<z; t++)
  31. {
  32. tab[i][j][t]=rand()%11-5;
  33. }
  34. }
  35. }
  36. //-------------------------------------------------------------
  37. int k;
  38. cout<<"Podaj ilosc tablic na jakie mam podzielic tablice trojwymiarowa"<<endl;
  39. cin>>k;
  40. char znak;
  41. cout<<"Teraz podaj wedlug ktorego wymiaru mam pociac tablice (x,y lub z)."<<endl;
  42. cin>>znak;
  43.  
  44.  
  45. int zmienna=0;
  46. if(znak=='x')
  47. {
  48. for(int i=0; i<x; i++)
  49. {
  50. if(k!=0)
  51. {
  52. k--;
  53. cout<<endl;
  54. }
  55.  
  56. for(int j=0; j<y; j++)
  57. {
  58. cout.width(2);
  59. cout<<tab[i][j][z-1]<<" ";
  60. }
  61. if(k==0)break;
  62. }
  63. }
  64. else if(znak=='y')
  65. {
  66. for(int i=0; i<x; i++)
  67. {
  68. if(k!=0)
  69. {
  70. k--;
  71. cout<<endl;
  72. }
  73.  
  74. for(int j=0; j<z; j++)
  75. {
  76. cout.width(2);
  77. cout<<tab[i][y-1][j]<<" ";
  78. }
  79. if(k==0)break;
  80. }
  81. }
  82. else if(znak=='z')
  83. {
  84. for(int i=0; i<x; i++)
  85. {
  86. if(k!=0)
  87. {
  88. k--;
  89. cout<<endl;
  90. }
  91.  
  92. for(int j=0; j<z; j++)
  93. {
  94. cout.width(2);
  95. cout<<tab[x-1][i][j]<<" ";
  96. }
  97. if(k==0)break;
  98. }
  99. }
  100. else cout<<"Bledny znak"<<endl;
  101. //-------------------------------------------------------------
  102. for (int i=0; i<x; i++) //usuniecie tablicy ***
  103. {
  104. for (int j=0; j<y; j++)
  105. {
  106. delete []tab[i][j];
  107. }
  108. delete []tab[i];
  109. }
  110. delete []tab;
  111. return 0;
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement