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

C++Server Side ProgrammingProgramming

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
raja
Published on 19-Dec-2019 10:41:49
Advertisements