##
Print all even number in c *programming*

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

**logic**:
The rule is, 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 odd or even, we need to simply divide the number by 2.

If there is any reminder left, or if there is any value of 5 mod 2 left, that means 5 is not divisible by 2. So 5 is odd number.

#### Algorithm

So the algorithm become

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 "

Don't see the code now. At first try is yourself and then go to see the code in c programming to print all even number.

**" is clear now. So now time to implement this in c programming.Again now you are able to "***How to print all even number in c programming***".***print all odd number in c programming*Don't see the code now. At first try is yourself and then go to see the code in c programming to print all even number.

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

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

ReplyDeleteHere you are checking 30 whether 30 is odd or even. As 30 mod 2 = 0, 30 is even.

DeleteIn case of 15, 15 mod 2 != 0, so 15 is odd...

Programming is combination of intelligent and creative work. Programmers can do anything with code. The entire Programming tutorials that you mention here on this blog are awesome. Beginners Heap also provides latest tutorials of Programming from beginning to advance level.

ReplyDeleteBe with us to learn programming in new and creative way.

Thank you!

Delete