![]() |
VOOZH | about |
Program to print first 10 even numbers. A number is even if it is divisible by 2 for example 4, 100, 24 etc.
0 2 4 6 8 10 12 14 16 18
Approach: Checking Parity using Modulo operator(%)
Using the modulo % operator we can find the remainder of any number when divided by 2, giving us the parity according to two cases:
- remainder = 0: Even number
- remainder = 1: Odd number
While we do not get first 10 even numbers, we can use the above method to check the parity and print the even numbers.
Step-by-step algorithm:
First 10 even numbers are: 0 2 4 6 8 10 12 14 16 18
Time Complexity: O(1)
Auxiliary Space: O(1)