using namespace std;
WHat is wrong in the code
This executes n+1 times, I think you are taking more input than required.
You are right . May be you have to begin from i=1 .