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?

Recommended Answers

All 3 Replies

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.

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 :)

Thank you Sneaker your input was helpfull.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.