fork(1) download
  1. #include <stdio.h>
  2.  
  3. // Reflect image horizontally
  4. void reflect(int height, int width, int image[height][width])
  5. {
  6. int temp;
  7.  
  8. for (int i = 0; i < height; i++)
  9. {
  10. for (int j = 0; j < width / 2; j++)
  11. {
  12. temp = image[i][j];
  13. image[i][j] = image[i][width - j - 1];
  14. image[i][width - j - 1] = temp;
  15. }
  16. }
  17. return;
  18. }
  19.  
  20. void print(int height, int width, int image[height][width])
  21. {
  22. for (int row = 0; row < height; row++) {
  23. for (int col = 0; col < width; col++) {
  24. printf("%2d ", image[row][col]);
  25. }
  26. puts("");
  27. }
  28. }
  29.  
  30. #define ROWS 5
  31. #define COLS 6
  32. int main(void) {
  33. int image[ROWS][COLS];
  34. for (int row = 0, i = 1; row < ROWS; row++) {
  35. for (int col = 0; col < COLS; col++) {
  36. image[row][col] = i++;
  37. }
  38. }
  39. print(ROWS, COLS, image);
  40. reflect(ROWS, COLS, image);
  41. puts("");
  42. print(ROWS, COLS, image);
  43. return 0;
  44. }
  45.  
Success #stdin #stdout 0s 4492KB
stdin
Standard input is empty
stdout
 1  2  3  4  5  6 
 7  8  9 10 11 12 
13 14 15 16 17 18 
19 20 21 22 23 24 
25 26 27 28 29 30 

 6  5  4  3  2  1 
12 11 10  9  8  7 
18 17 16 15 14 13 
24 23 22 21 20 19 
30 29 28 27 26 25