I took both of your code snippets (Program 1 and Program 2), compiled and ran. Both ran, no problems.
Note: variable-sized arrays are not supported under Microsoft platform. But OnlineGDB runs on Linux, so we're good.
So, I don't understand your question. I don't see any problems in either Program 1 or Program 2.