using namespace std;
getting wrong answer please help
Add a newline character after the output…!
Just add ‘\n’ after printf.
work on this…
In case of ties, choose the smaller element first.
it is not handled in your case…
and also increase the size of array z to 10001, actually, you need to count integer 10000 also… so z++ will give runtime error in your case
Corrections in your code ->
you have to reinitialize the ans to 0, you have not done that,
also add return 0 before main() ends,
memset(z,0,10000) is the mistake in your code.
it should be memset(z,0,sizeof(z)).
@ dracowane thanks a lot i understood it now !!
@rjohari23 it is not necessary to write ‘return 0’ if you are using C++ . It automatically returns 0 if nothing is mentioned ,
quoting from bjarne stroutrup :-
It’s also worth noting that in C++, int main() can be left without a return value at which point it defaults to returning 0. This is also true with a C99 program. Whether return 0 should be omitted or not is open to debate .