Jump to content
yrstruly

Output Of Numbers

Recommended Posts

HelloDoes anybody know of any sources of codes that i can find somewhere, which does the following?Write a program that prints all even numbers from 2 to 100 inclusive?

Share this post


Link to post
Share on other sites

You don't need special code for that. You need to make a loop. You need to print. And you need to understand the modulo operator, sometimes called the remainder operator. It works the same in all languages, and telling odd numbers from even is its most common use. It looks like a percent sign: %

Share this post


Link to post
Share on other sites

For a setup where you need to test whether a number is odd or even, the modulo operator that Dad mentions is the way to go. For a simple setup like you've described, you could also use a for loop where the iterator is initialized at 2 and is incremented by two over each iteration.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...