- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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
#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
Advertisements