### Stuck in Arrays

I have created an array. There are two arrays, I want to print larger than 50 values in the s[j] array.

It should be like this
 `70 92 68 90 99 0 0 0 0 0`

But I don't know why my array prints like this.
 `0 70 92 68 68 90 99 99 99 99`

There should be a small mistake. Here is the code. Kindly someone help me to correct this. Thanks.

 ``123456789101112131415161718`` ``````#include using namespace std; int t[10]={40, 70, 92, 68, 43,90, 99, 23, 45, 1}; int s[10]; int main() { for (int j=0,i=0; i < 10; i++) { if (t[i]>=50) s[j]=t[i]; cout << s[j] << "\t"; } cout << endl; return 0; }``````
 ``123456789101112131415161718`` ``````#include using namespace std; int t[10]={40, 70, 92, 68, 43,90, 99, 23, 45, 1}; int s[10]; int main() { for (int j=0,i=0; i < 10; i++) { if (t[i]>=50) s[j]=t[i]; cout << s[j] << "\t"; } cout << endl; return 0; }``````

Note that j never changes in your program. It is always 0.

I have changed it like this
 ``123`` ``````s[j]=t[i]; cout << s[j] << "\t"; s[j++];``````

Now the out put is like
 `0 70 92 68 0 90 99 0 0 0`

I want to rearrange it as zeros to end and others from s[0].
After doing following changes it showed,
 ``1234567`` ``````if (t[i]>=50){ s[j]=t[i]; cout << s[j] << "\t"; s[j++]; } } cout << endl;``````

I forgot to add 2 curl brackets between if condition.

Now its
 `70 92 68 90 99`

Thank you for the help.
Last edited on
Topic archived. No new replies allowed.