Program to print all the numbers divisible by 3 and 5 in C++


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

 Live Demo

#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

Updated on: 19-Dec-2019

886 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements