In this tutorial, we will be discussing a program to print all the numbers divisible by 3 and 5 less than the given number.
For this we will be given with a number say N. Our task is to print all the numbers less than N which are divisible by both 3 and 5.
Example
#include <iostream>
using namespace std;
//printing the numbers divisible by 3 and 5
void print_div(int N){
for (int num = 0; num < N; num++){
if (num % 3 == 0 && num % 5 == 0)
cout << num << " ";
}
}
int main(){
int N = 70;
print_div(N);
return 0;
}Output
0 15 30 45 60