here is the link to my code:
https://ide.codingblocks.com/s/196723
please help me ;
the logic is that for generating prime number i have generated the prime sieve
and considered three stacks s1,s2,b1
I am doing it recursively in each recursive call i am printing b1 stack and making it empty and interchanging s1 and s2
Run time error is coming
Hello @Bhavit_Singla,
There are following corrections in your code:
-
int prime[1000];
There are only 25 prime number till 100.
It might be possible that the vale of Q is greater than 25. -
The logic you have applied for finding prime number is not optimal.
Refer to this link. -
int primenumber[100];
As you don’t know the numbers of prime numbers you are storing.
So, rather you a vector to store them. -
Pass s1 and s2 as reference rather than value in pile() function.
As you are printing s1 in main function. -
makepile(s1,s2,b1,prime[k]);
pile(s2,s1,b1,prime,n,k+=1);
before passing s1 as s2 in recursive call pile() make it empty.
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.