0

I need to write a program that will output a list of all even numbers between 1-100. It needs to use a while loop then use a for loop. Any one got any help on how to do that?

3
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by eshirley
0

You can easily write this with either a for loop or a while loop. You don't need both. Use the % (modulus) operator to tell if a number is even or not. If number % 2 == 0 then it is even.

1

I need to write a program that will output a list of all even numbers between 1-100. It needs to use a while loop then use a for loop. Any one got any help on how to do that?

If it is a task where you must have both kinds of loop you could do it like this:
While number is less than 100
check if it is even (see the answer BestJewSinceJC gave you)
put the even numbers in a array of int's
For every index in the int array make an outprint.

This is only one way to do it.
Good luck :)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.