# Program to print all the numbers divisible by 3 and 5 for a given number

## Program to print all the numbers divisible by 3 and 5 for a given number

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 implementation :

 `// C++ program to print all the numbers` `// divisible by 3 and 5 for a given number` `#include ` `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)`

Output :

`0 15 30 45 60 75 90`

Last Updated on October 24, 2021 by admin

## Arrays in C/C++Arrays in C/C++

Arrays in C/C++ An array in C/C++ or be it in any programming language is a collection of similar data items stored at contiguous memory locations and elements can be accessed randomly using indices of an array.  They can be

## Count occurrences of a word in stringCount occurrences of a word in string

Count occurrences of a word in string You are given a string and a word your task is that count the number of the occurrence of the given word in the string and print the number of occurrences of the

## Is sizeof for a struct equal to the sum of sizeof of each member?Is sizeof for a struct equal to the sum of sizeof of each member?

Is sizeof for a struct equal to the sum of sizeof of each member? The sizeof for a struct is not always equal to the sum of sizeof of each individual member. This is because of the padding added by

## Program to calculate Electricity BillProgram to calculate Electricity Bill

Program to calculate Electricity Bill Given an integer U denoting the amount of KWh units of electricity consumed, the task is to calculate the electricity bill with the help of the below charges: 1 to 100 units –  100 to 200 units

## Array of Strings in C++Array of Strings in C++

Array of Strings in C++ (All Different Ways to Create) In C and C++, a string is a 1-dimensional array of characters and an array of strings in C is a 2-dimensional array of characters. There are many ways to

## Program to print the diamond shapeProgram to print the diamond shape

Program to print the diamond shape Given a number n, write a program to print a diamond shape with 2n rows. Examples : // C++ program to print diamond shape // with 2n rows #include <bits/stdc++.h> using namespace std; //

## Program to generate all possible valid IP addresses from given stringProgram to generate all possible valid IP addresses from given string

Program to generate all possible valid IP addresses from given string Given a string containing only digits, restore it by returning all possible valid IP address combinations. A valid IP address must be in the form of A.B.C.D, where A,

## Generating subarrays using recursionGenerating subarrays using recursion

Generating subarrays using recursion Given an array, generate all the possible subarrays of the given array using recursion. Examples:   Input : [1, 2, 3] Output : [1], [1, 2],[1,3], [2], [1, 2, 3], [2, 3], [3] Input : [1,