![]() |
VOOZH | about |
Given an integer n, the task is to print all the numbers less than N that are divisible by both 3 and 5. A number divisible by both must be divisible by their LCM = 15. For Example:
Input: 50
Output: 0 15 30 45
This method uses a for loop that jumps directly in steps of 15, since every number divisible by both 3 and 5 must be a multiple of 15. Thus, we avoid checking every number.
0 15 30 45 60 75 90
Explanation:
This method checks divisibility using a single modulo condition. If a number is divisible by 15, it is divisible by both 3 and 5.
0 15 30 45 60 75 90
Explanation:
This method checks divisibility by checking both conditions separately.
0 15 30 45 60 75 90
Explanation:
This method generates all required numbers in a single expression and prints them.
0 15 30 45 60 75 90
Explanation: