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

Gifts for programmers

Best laptop for Excel

$
Gifts for programmers

Best laptop for Solidworks

$399+
Gifts for programmers

Best laptop for Roblox

$399+
Gifts for programmers

Best laptop for development

$499+
Gifts for programmers

Best laptop for Cricut Maker

$299+
Gifts for programmers

Best laptop for hacking

$890
Gifts for programmers

Best laptop for Machine Learning

$699+
Gifts for programmers

Raspberry Pi robot kit

$150

Latest questions

PythonStackOverflow

Common xlabel/ylabel for matplotlib subplots

1947 answers

PythonStackOverflow

Check if one list is a subset of another in Python

1173 answers

PythonStackOverflow

How to specify multiple return types using type-hints

1002 answers

PythonStackOverflow

Printing words vertically in Python

909 answers

PythonStackOverflow

Python Extract words from a given string

798 answers

PythonStackOverflow

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

606 answers

PythonStackOverflow

Python os.path.join () method

384 answers

PythonStackOverflow

Flake8: Ignore specific warning for entire file

360 answers

News


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

Python add suffix / add prefix to strings in a list

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

Python - Move item to the end of the list

Python - Print list vertically