#include <stdio.h>
#include <stddef.h>
#include <inttypes.h>
void delta(uint8_t arr_in[5][5], uint8_t arr_out[5][5])
{
arr_out[0][0] = arr_in[0][0];
for (size_t ix = 1; ix < 5; ix++)
{
arr_out[0][ix] = arr_in[0][ix] - arr_in[0][ix-1];
}
for (size_t iy = 1; iy < 5; iy++)
{
for (size_t ix = 0; ix < 5; ix++)
{
arr_out[iy][ix] = arr_in[iy][ix] - arr_in[iy-1][ix];
}
}
}
void print_2d(uint8_t arr_in[5][5])
{
for (size_t iy = 0; iy < 5; iy++)
{
for (size_t ix = 0; ix < 5; ix++)
{
printf("0x%02" PRIx8
" ", arr_in
[iy
][ix
]); }
}
}
int main(void) {
uint8_t arr_in[][5] =
{
{0x00, 0x02, 0x04, 0x06, 0x08},
{0x01, 0x03, 0x05, 0x07, 0x09},
{0x02, 0x04, 0x06, 0x08, 0x0A},
{0x03, 0x05, 0x07, 0x09, 0x0B},
{0x04, 0x06, 0x08, 0x0A, 0x0C}
};
uint8_t arr_out1[5][5];
uint8_t arr_out2[5][5];
delta(arr_in,arr_out1);
print_2d(arr_out1);
delta(arr_out1,arr_out2);
print_2d(arr_out2);
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRkZWYuaD4KI2luY2x1ZGUgPGludHR5cGVzLmg+Cgp2b2lkIGRlbHRhKHVpbnQ4X3QgYXJyX2luWzVdWzVdLCB1aW50OF90IGFycl9vdXRbNV1bNV0pCnsKICBhcnJfb3V0WzBdWzBdID0gYXJyX2luWzBdWzBdOwogIGZvciAoc2l6ZV90IGl4ID0gMTsgaXggPCA1OyBpeCsrKQogIHsKICAJYXJyX291dFswXVtpeF0gPSBhcnJfaW5bMF1baXhdIC0gYXJyX2luWzBdW2l4LTFdOwogIH0KICBmb3IgKHNpemVfdCBpeSA9IDE7IGl5IDwgNTsgaXkrKykKICB7CiAgCWZvciAoc2l6ZV90IGl4ID0gMDsgaXggPCA1OyBpeCsrKQogICAgewogICAgICBhcnJfb3V0W2l5XVtpeF0gPSBhcnJfaW5baXldW2l4XSAtIGFycl9pbltpeS0xXVtpeF07CiAgICB9CiAgfQp9Cgp2b2lkIHByaW50XzJkKHVpbnQ4X3QgYXJyX2luWzVdWzVdKQp7CiAgZm9yIChzaXplX3QgaXkgPSAwOyBpeSA8IDU7IGl5KyspCiAgewogIAlmb3IgKHNpemVfdCBpeCA9IDA7IGl4IDwgNTsgaXgrKykKICAgIHsKICAgICAgcHJpbnRmKCIweCUwMiIgUFJJeDggIiAiLCBhcnJfaW5baXldW2l4XSk7CiAgICB9CiAgICBwcmludGYoIlxuIik7CiAgfQp9CgoKaW50IG1haW4odm9pZCkgewogIHVpbnQ4X3QgYXJyX2luW11bNV0gPQogIHsKICAgIHsweDAwLCAweDAyLCAweDA0LCAweDA2LCAweDA4fSwKICAgIHsweDAxLCAweDAzLCAweDA1LCAweDA3LCAweDA5fSwKICAgIHsweDAyLCAweDA0LCAweDA2LCAweDA4LCAweDBBfSwKICAgIHsweDAzLCAweDA1LCAweDA3LCAweDA5LCAweDBCfSwKICAgIHsweDA0LCAweDA2LCAweDA4LCAweDBBLCAweDBDfQogIH07CiAgdWludDhfdCBhcnJfb3V0MVs1XVs1XTsKICB1aW50OF90IGFycl9vdXQyWzVdWzVdOwogIGRlbHRhKGFycl9pbixhcnJfb3V0MSk7CiAgcHJpbnRfMmQoYXJyX291dDEpOwogIHByaW50ZigiXG4iKTsKICBkZWx0YShhcnJfb3V0MSxhcnJfb3V0Mik7CiAgcHJpbnRfMmQoYXJyX291dDIpOwogIHJldHVybiAwOwp9Cg==