Advertisement
WachidSusilo

Transverse Matrix Arduino

Oct 24th, 2020
741
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.76 KB | None | 0 0
  1. int array1[5][2] = {
  2.   {1, 2},
  3.   {3, 4},
  4.   {5, 6},
  5.   {7, 8},
  6.   {9, 10}
  7. };
  8.  
  9. void transverse(int *target, int *container, int row, int column) {
  10.   for (int i = 0; i < row; i++) {
  11.     for (int j = 0; j < column; j++) {
  12.       *(container + j * row + i) = *(target + i * column + j);
  13.     }
  14.   }
  15. }
  16.  
  17. void printArray(int *target, int row, int column) {
  18.   Serial.println();
  19.   for (int i = 0; i < row; i++) {
  20.     for (int j = 0; j < column; j++) {
  21.       Serial.print(*(target + i * column + j));
  22.       Serial.print("\t");
  23.     }
  24.     Serial.println();
  25.   }
  26. }
  27.  
  28. void setup() {
  29.   Serial.begin(115200);
  30.   printArray((int*)array1, 5, 2);
  31.  
  32.   int array2[2][5];
  33.   transverse((int*)array1, (int*)array2, 5, 2);
  34.   printArray((int*)array2, 2, 5);
  35. }
  36.  
  37. void loop() {}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement