0
Value of array index not increasing.
for(int i=1; i<=num; i++){ if(i%2!=0){ prime [x] = i; count++; } } Here if the condition occurs the value of i store in the array prime. But the index of the array is not increasing, all the values are storing at [0] index and destroy the previous value. Try all the other methods but didn't find anything. Please help.
3 Antworten
+ 4
Where is the declaration of <x> and <count>? assuming <x> initialized to zero, you can do prime[x++] = i; that is if you use <x> for array index, not sure what <count> here is for.
+ 3
Alright, good to know you have it solved. Good job : )
+ 1
count is here for how many times my for loop worked, and yeah I tried prime[x++] and prime[x+1], but they both didn't work for me. I have another solution then I'll be very thankful to yours.