Change language

# Program for printing all numbers divisible by 3 and 5 for a given number

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 the limit, then the program should print all numbers less than 20 that are divisible by 3 and 5. To do this, divide each number from 0 to N by 3 and 5 and check their remainder ... If the remainder is 0 in both cases, just print that number.

Below is the implementation:

C++

 ` // C++ program for printing all numbers ` ` // divisible by 3 and 5 for 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 used ` ` if ` ` (num% 3 == 0 & amp; & amp; num% 5 == 0) ` ` ` ` cout "& lt; num "& lt; ` ` "" ` `; ` `} ` `} ` ` `  ` // Driver code ` ` int ` ` main () ` ` { ` ` // login goes here ` ` int ` ` N = 100; `   ` // Calling function ` ` ` ` result (N); ` ` return ` ` 0; ` `} `   ` // This code is provided by Manish Shaw ` ` // (manishshaw1) `

Java

 ` // Java program for printing all 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 & lt; N; num ++) ` ` { ` ` // short-circuit operator used ` ` if ` ` (num% ` ` 3 ` ` == ` ` 0 ` ` & amp; & amp; num% ` ` 5 ` ` == ` ` 0 ` `) ` ` System.out.print (num + ` `" "` `); ` `} ` `} ` ` `  ` // Driver code ` ` public ` ` static ` ` void ` ` main (String [] args) ` ` {` ` // login goes here ` ` ` ` int ` ` N = ` ` 100 ` `; `   ` // Calling function ` ` ` ` result (N); ` `} ` `} `

python3

` `

` # Python program to print all 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 used if num % 3 = = 0 and num % 5 = = 0 : print ( str (num) + " " , end = " ")    else : pass    # Driver code if __ name__ = = "__ main__" :      # login goes here N = 100   # Function call result (N) `

` ` C #

 ` // C # program for printing all 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 ++) ` ` { ` ` // use short-circuit statement ` ` if ` ` ( num% 3 == 0 & amp; & amp; num% 5 == 0) ` ` Console.Write (num + ` ` "" ` `); ` `} ` `} ` ` `  ` // Driver code ` ` static ` ` public ` ` void ` ` Main () {` ` // login goes here ` ` ` ` int ` ` N = 100; ` ` // Calling function ` ` result (N); ` `} ` ` // This code is provided by ajit. ` `} `

PHP

 ` & lt;? php ` ` // PHP program to print all 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 ` ` & lt; ` ` \$ N ` `; ` ` \$ num ` ` ++) ` ` { ` ` // short-circuit operator is used ` ` if ` ` (` ` \$ num ` `% 3 == 0 & amp; & amp; ` ` \$ num ` `% 5 == 0) ` ` echo ` ` \$ num ` `, ` ` "" ` `; ` `} ` `} ` ` `  ` // Driver code `   ` // login goes here ` ` \$ N ` ` = 100; `   ` // Calling function ` ` result (` ` \$ N ` `); `   ` // This code is provided by ajit ` `?" `

Output:

` 0 15 30 45 60 75 90 `

## Shop

Best laptop for Excel

\$

Best laptop for Solidworks

\$399+

Best laptop for Roblox

\$399+

Best laptop for development

\$499+

Best laptop for Cricut Maker

\$299+

Best laptop for hacking

\$890

Best laptop for Machine Learning

\$699+

Raspberry Pi robot kit

\$150

Latest questions

PythonStackOverflow

Common xlabel/ylabel for matplotlib subplots

PythonStackOverflow

Check if one list is a subset of another in Python

PythonStackOverflow

How to specify multiple return types using type-hints

PythonStackOverflow

Printing words vertically in Python

PythonStackOverflow

Python Extract words from a given string

PythonStackOverflow

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

PythonStackOverflow

Python os.path.join () method

PythonStackOverflow

Flake8: Ignore specific warning for entire file

## Wiki

Python | How to copy data from one Excel sheet to another

Common xlabel/ylabel for matplotlib subplots

Check if one list is a subset of another in Python

How to specify multiple return types using type-hints

Printing words vertically in Python

Python Extract words from a given string

Cyclic redundancy check in Python

Finding mean, median, mode in Python without libraries