Difference in execution time in C and C++

The code is not really the same even though they do the same thing

The c++ version uses cin and streams which are slower than scanf etc by default.

By default, cin/cout waste time synchronizing themselves with the C library’s stdio buffers, so that you can freely intermix calls to scanf/printf with operations on cin/cout. You can turn this off with std::ios_base::sync_with_stdio(false);

By doing this the time taken will more or less be similar I would expect