Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. #include <iostream>
  2. #include <ctime>
  3.  
  4. using namespace std;
  5. const int n = 5, m = 5;
  6.  
  7. void fun(int a[]) {
  8. int b[m][n];
  9. cout << "\n\nArray#2:\n";
  10. for (int i = 0; i < n; i++) {
  11. for (int j = 0; j < m; j++) {
  12. if (m > n)b[j][i] = a[n * i + j];
  13. else b[j][i] = a[m * i + j];
  14. cout << b[j][i] << "\t";
  15. }
  16. cout << "\n\n";
  17. }
  18. cout << "\nArray#2`:\n";
  19. for (int i = 0; i < m; i++) {
  20. for (int j = 0; j < n; j++) {
  21. if (m > n)a[n * i + j] = b[i][j];
  22. else a[m * i + j] = b[i][j];
  23. cout << b[i][j] << "\t";
  24. }
  25. cout << "\n\n";
  26. }
  27. }
  28.  
  29.  
  30.  
  31. int main() {
  32. srand(time(0));
  33. int a[n * m];
  34. cout << "Array#1:\n";
  35. for (int i = 0; i < n * m; i++) {
  36. a[i] = rand() % 10;
  37. cout << a[i] << " ";
  38. }
  39. fun(a);
  40. cout << "\nArray#1`:\n";
  41. for (int i = 0; i < n * m; i++) {
  42. cout << a[i] << " ";
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement