fork download
  1. #include <stdio.h>
  2. #include <stddef.h>
  3. #include <inttypes.h>
  4.  
  5. void delta(uint8_t arr_in[5][5], uint8_t arr_out[5][5])
  6. {
  7. arr_out[0][0] = arr_in[0][0];
  8. for (size_t ix = 1; ix < 5; ix++)
  9. {
  10. arr_out[0][ix] = arr_in[0][ix] - arr_in[0][ix-1];
  11. }
  12. for (size_t iy = 1; iy < 5; iy++)
  13. {
  14. for (size_t ix = 0; ix < 5; ix++)
  15. {
  16. arr_out[iy][ix] = arr_in[iy][ix] - arr_in[iy-1][ix];
  17. }
  18. }
  19. }
  20.  
  21. void print_2d(uint8_t arr_in[5][5])
  22. {
  23. for (size_t iy = 0; iy < 5; iy++)
  24. {
  25. for (size_t ix = 0; ix < 5; ix++)
  26. {
  27. printf("0x%02" PRIx8 " ", arr_in[iy][ix]);
  28. }
  29. printf("\n");
  30. }
  31. }
  32.  
  33.  
  34. int main(void) {
  35. uint8_t arr_in[][5] =
  36. {
  37. {0x00, 0x02, 0x04, 0x06, 0x08},
  38. {0x01, 0x03, 0x05, 0x07, 0x09},
  39. {0x02, 0x04, 0x06, 0x08, 0x0A},
  40. {0x03, 0x05, 0x07, 0x09, 0x0B},
  41. {0x04, 0x06, 0x08, 0x0A, 0x0C}
  42. };
  43. uint8_t arr_out1[5][5];
  44. uint8_t arr_out2[5][5];
  45. delta(arr_in,arr_out1);
  46. print_2d(arr_out1);
  47. printf("\n");
  48. delta(arr_out1,arr_out2);
  49. print_2d(arr_out2);
  50. return 0;
  51. }
  52.  
Success #stdin #stdout 0s 2112KB
stdin
Standard input is empty
stdout
0x00 0x02 0x02 0x02 0x02 
0x01 0x01 0x01 0x01 0x01 
0x01 0x01 0x01 0x01 0x01 
0x01 0x01 0x01 0x01 0x01 
0x01 0x01 0x01 0x01 0x01 

0x00 0x02 0x00 0x00 0x00 
0x01 0xff 0xff 0xff 0xff 
0x00 0x00 0x00 0x00 0x00 
0x00 0x00 0x00 0x00 0x00 
0x00 0x00 0x00 0x00 0x00