error in the code
Playing with cards
Hello @Vibhuti0206,
Your code is logically incorrect as it is showing wrong answer for the sample test case given in the question.
- The prime function should return the ith prime number.
1.1. But it is returning 2 for each call.
Reason:
for(int i=0;i<q;i++)
{
if(p[i])
{
return i;
}
}
The above code will return i=2 as a[2] is 1.
1.2. your code is creating an array to store 0 and 1 (i.e. not-prime and prime) for elements 0 to q.
But this won’t include the qth prime number.
1.3. you have created the array p with size q indexed from 0 to q-1.
But you are using p[q].
-
You are copying s3 to s1 outside the for-loop.
Do it inside the for loop and after that empty the stack s3. -
Outside the for-loop, do not print the content of stack s3.
Correct the above.
Hope, this would help.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.