Given the integer N, the task is to print all the numbers less than N, which are divisible by 3 and 5.

**Examples :**

Input : 50 Output : 0 15 30 45 Input : 100 Output : 0 15 30 45 60 75 90

**Approach : ** For example, let’s take N = 20 as a limit, then the program should print all numbers less than 20 which are divisible by both 3 and 5. For this divide each number from 0 to N by both 3 and 5 and check their remainder. If remainder is 0 in both cases then simply print that number.

Below is the implementaion :

## C++

`// C++ program to print all the numbers ` `// divisible by 3 and 5 for a given number ` `#include <iostream> ` `using` `namespace` `std; ` ` ` `// Result function with N ` `void` `result(` `int` `N) ` `{ ` ` ` `// iterate from 0 to N ` ` ` `for` `(` `int` `num = 0; num < N; num++) ` ` ` `{ ` ` ` `// Short-circuit operator is used ` ` ` `if` `(num % 3 == 0 && num % 5 == 0) ` ` ` `cout << num << ` `" "` `; ` ` ` `} ` `} ` ` ` `// Driver code ` `int` `main() ` `{ ` ` ` `// input goes here ` ` ` `int` `N = 100; ` ` ` ` ` `// Calling function ` ` ` `result(N); ` ` ` `return` `0; ` `} ` ` ` `// This code is contributed by Manish Shaw ` `// (manishshaw1) ` |

*chevron_right*

*filter_none*

## Java

`// Java program to print all the numbers ` `// divisible by 3 and 5 for a given number ` ` ` `class` `GFG{ ` ` ` ` ` `// Result function with N ` ` ` `static` `void` `result(` `int` `N) ` ` ` `{ ` ` ` `// iterate from 0 to N ` ` ` `for` `(` `int` `num = ` `0` `; num < N; num++) ` ` ` `{ ` ` ` `// Short-circuit operator is used ` ` ` `if` `(num % ` `3` `== ` `0` `&& num % ` `5` `== ` `0` `) ` ` ` `System.out.print(num + ` `" "` `); ` ` ` `} ` ` ` `} ` ` ` ` ` `// Driver code ` ` ` `public` `static` `void` `main(String []args) ` ` ` `{ ` ` ` `// input goes here ` ` ` `int` `N = ` `100` `; ` ` ` ` ` `// Calling function ` ` ` `result(N); ` ` ` `} ` `} ` |

*chevron_right*

*filter_none*

## Python3

`# Python program to print all the numbers ` `# divisible by 3 and 5 for a given number ` ` ` `# Result function with N ` `def` `result(N): ` ` ` ` ` `# iterate from 0 to N ` ` ` `for` `num ` `in` `range` `(N): ` ` ` ` ` `# Short-circuit operator is used ` ` ` `if` `num ` `%` `3` `=` `=` `0` `and` `num ` `%` `5` `=` `=` `0` `: ` ` ` `print` `(` `str` `(num) ` `+` `" "` `, end ` `=` `"") ` ` ` ` ` `else` `: ` ` ` `pass` ` ` `# Driver code ` `if` `__name__ ` `=` `=` `"__main__"` `: ` ` ` ` ` `# input goes here ` ` ` `N ` `=` `100` ` ` ` ` `# Calling function ` ` ` `result(N) ` |

*chevron_right*

*filter_none*

## C#

`// C# program to print all the numbers ` `// divisible by 3 and 5 for a given number ` `using` `System; ` `public` `class` `GFG{ ` ` ` ` ` `// Result function with N ` ` ` `static` `void` `result(` `int` `N) ` ` ` `{ ` ` ` `// iterate from 0 to N ` ` ` `for` `(` `int` `num = 0; num < N; num++) ` ` ` `{ ` ` ` `// Short-circuit operator is used ` ` ` `if` `(num % 3 == 0 && num % 5 == 0) ` ` ` `Console.Write(num + ` `" "` `); ` ` ` `} ` ` ` `} ` ` ` ` ` `// Driver code ` ` ` `static` `public` `void` `Main (){ ` ` ` `// input goes here ` ` ` `int` `N = 100; ` ` ` `// Calling function ` ` ` `result(N); ` ` ` `} ` `//This code is contributed by ajit. ` `} ` |

*chevron_right*

*filter_none*

## PHP

`<?php ` `// PHP program to print all the numbers ` `// divisible by 3 and 5 for a given number ` ` ` `// Result function with N ` `function` `result(` `$N` `) ` `{ ` ` ` `// iterate from 0 to N ` ` ` `for` `(` `$num` `= 0; ` `$num` `< ` `$N` `; ` `$num` `++) ` ` ` `{ ` ` ` `// Short-circuit operator is used ` ` ` `if` `(` `$num` `% 3 == 0 && ` `$num` `% 5 == 0) ` ` ` `echo` `$num` `, ` `" "` `; ` ` ` `} ` `} ` ` ` `// Driver code ` ` ` `// input goes here ` `$N` `= 100; ` ` ` `// Calling function ` `result(` `$N` `); ` ` ` `// This code is contributed by ajit ` `?> ` |

*chevron_right*

*filter_none*

**Output :**

0 15 30 45 60 75 90

Attention geek! Strengthen your foundations with the **Python Programming Foundation** Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the **Python DS** Course.

## Recommended Posts:

- Program to print all the numbers divisible by 5 or 7 for a given number
- Print k numbers where all pairs are divisible by m
- Python Program to Print all Integers that Aren't Divisible by Either 2 or 3
- Python Program for Efficient program to print all prime factors of a given number
- Count numbers which are divisible by all the numbers from 2 to 10
- Count of N-digit Numbers having Sum of even and odd positioned digits divisible by given numbers
- Python Program to Find Numbers Divisible by 7 and Multiple of 5 in a Given Range
- Count of numbers upto M divisible by given Prime Numbers
- Python program to print all Strong numbers in given list
- Sum of all numbers divisible by 6 in a given range
- C++ program to print all Even and Odd numbers from 1 to N
- Python Program to check whether it is possible to make a divisible by 3 number using all digits in an array
- Divide number into two parts divisible by given numbers
- Smallest n digit number divisible by given three numbers
- Count n digit numbers divisible by given number
- Sum of n digit numbers divisible by a given number
- C Program to Print all digits of a given number
- Python program to print all negative numbers in a range
- Python program to print all Prime numbers in an Interval
- Python program to print all even numbers in a range

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.