I submitted the following code for the problem Uncle Johny.I know the other approach but I am unable to spot an error in this one…i am getting wrong answer everytime.It runs well on all the cases I typed in.Please help.
using namespace std;
while(up>down && up>0 && down<=n)
As @damn_me said, please post your code in proper blocks, this is a little difficult to read.
My solution, I stored the kth element of the array in some temporary variable and then sorted the array in ascending order. The rest is just going through the array and printing the index of the array, when the element matches our temporary variable.
You could simply iterate through through the array and count the number of elements smaller than the kth element, and then add 1 to know its position.
Here is a solution using the first method: http://ideone.com/RqjBJQ
Please, put your code in proper blocks or ideone link. Can you also read it? It’s very tough to test this manner. (No offense please)