How to print all even number in c programming (logic)

Print all even numbers in c programming

To print all even numbers from a range in c programming, we have to check all numbers between the given range. To check if the number is odd or even number, we can use the following logic:

If any number is fully divided by 2, then this number is even. Else the number is odd. 
Even and Odd

For example

If we want to check whether the number 5 is odd or even, we need to simply divide the number by 2.
If there is any remainder left or any value of 5 mod 2 left, that means 5 is not divisible by 2. So 5 is an odd number.


So the algorithm becomes.

if(number % 2 == 0){
                  number is even;
else if(number % 2 != 0){
                  number is odd;
[Note: here "%" sign is to calculate mod or remainder of division]

I hope the logical part of "How to print all even numbers in c programming" is clear now. So now time to implement this in c programming. Again now you can "print all odd numbers in c programming."
Don't see the code now. At first, try it yourself and then go to see the code in c programming to print all even numbers.

--------------------- Happy Coding ------------------------

Now time to practice the following:

Star printing pattern in c/java                            Calculate mod in c programming           

3/Post a Comment/Comments

  1. But 30 ÷ 2 = 15 leaving no remainder 15 is odd

    1. Here you are checking 30 whether 30 is odd or even. As 30 mod 2 = 0, 30 is even.
      In case of 15, 15 mod 2 != 0, so 15 is odd...

  2. I am glad that I saw this post. It is informative blog for us and we need this type of blog thanks for share this blog, Keep posting such instructional blogs and I am looking forward for your future posts. Python Projects for Students Data analytics is the study of dissecting crude data so as to make decisions about that data. Data analytics advances and procedures are generally utilized in business ventures to empower associations to settle on progressively Python Training in Chennai educated business choices. In the present worldwide commercial center, it isn't sufficient to assemble data and do the math; you should realize how to apply that data to genuine situations such that will affect conduct. In the program you will initially gain proficiency with the specialized skills, including R and Python dialects most usually utilized in data analytics programming and usage; Python Training in Chennai at that point center around the commonsense application, in view of genuine business issues in a scope of industry segments, for example, wellbeing, promoting and account. Project Center in Chennai


Post a Comment