I've got a problem with my code. It should show the random numbers in descending and ascending order, however sometimes it shows 0 at the first position in ascending order (even if min is higher) and sometimes it shows some weird big number in descending order. I think it has to do with the number of numbers in tab. Could somebody explain to me why this happens and what can I do with it?
Your arrays WILL be accessed out of bounds on lines 72 and 117, because they will be trying to access tab[size]. Try for (int j = 0; j < size - 1; j++)
(though the rest of your sorting routine is rather inefficient).
I don't know if that alone will solve your problem, but I think you should reformat your code with proper indentation before much else. It is very hard to read. It's more reliable on multiple platforms if you use spaces rather than tabs for indentation.