Mail Archives: djgpp/2000/10/20/08:15:14
Johan <khira_98 AT yahoo DOT com> wrote:
> Hi!
> 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.
At the moment, your code is putting the *sum* of all such entries into
array_b, not the individual ones. Get rid of the 'for (j=...)' loop.
> int array_a[] = {3, 2, 7, 0, 5, -4, 8, 7, -1, -9};
> int array_b[7];
> int n = 10;
> int m = 7;
A side issue: here, you're making assumptions about the number of
elements array_b is going to have, i.e. you're using part of the
solution to construct the program that is meant to find that solution.
You shouldn't do that. Make array_b as big as array_a, instead.
Start with m=0, and count it upwards as you find entries for array_b.
--
Hans-Bernhard Broeker (broeker AT physik DOT rwth-aachen DOT de)
Even if all the snow were burnt, ashes would remain.
- Raw text -