Mail Archives: djgpp/2000/10/20/09:34:21
> Date: Thu, 19 Oct 2000 14:46:48 -0400
> From: "Johan" <khira_98 AT yahoo DOT com>
>
> I have some problems with my program. I want to take
> the numbers in array_a that are positive. 0 or
above.
> And put these in array_b and print them out.
>
Your problem is in the way it loops. You only need
one "for" loop and the "j" should only get incremented
after you decide to keep the value in "array_a". Also
you only need to store the value of "array_a" in
"array_b" and not add it (unless you have a reason for
it). I stuck an additional check in the "for" loop so
the value in "j" doesn't go past the limit "m". So
here's how the fragment would look:
int j = 0;
for (int i = 0; i < n, j < m; i++)
{
if (array_a[i] >= 0)
{
array_b[j] = array_a[i];
j++;
}
}
- jModule
__________________________________________________
Do You Yahoo!?
Yahoo! Messenger - Talk while you surf! It's FREE.
http://im.yahoo.com/
- Raw text -