
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Multiples of 3 or 7 in C++
Given a number n, we need to find the count of multiples of 3 or 7 till n. Let's see an example.
Input
100
Output
43
There are total of 43 multiples of 3 or 7 till 100.
Algorithm
Initialise the number n.
Initialise the count to 0.
Write a loop that iterates from 3 to n.
Increment the count if the current number is divisible by 3 or 7.
Implementation
Following is the implementation of the above algorithm in C++
#include <bits/stdc++.h> using namespace std; int getMultiplesCount(int n) { int count = 0; for (int i = 3; i <= n; i++) { if (i % 3 == 0 || i % 7 == 0) { count++; } } return count; } int main() { cout << getMultiplesCount(100) << endl; }
Output
If you run the above code, then you will get the following result.
43
- Related Questions & Answers
- Find Multiples of 2 or 3 or 5 less than or equal to N in C++
- Multiples of 3 and 5 without using % operator in C++
- Sum of the series 1 + (1+3) + (1+3+5) + (1+3+5+7) + + (1+3+5+7+....+(2n-1)) in C++
- Sum of the series 1 + (1+3) + (1+3+5) + (1+3+5+7) + ...... + (1+3+5+7+...+(2n-1)) in C++
- 3 and 7 in Python
- Program to find N-th term of series 0, 2,1, 3, 1, 5, 2, 7, 3...in C++
- Find sum of the series 1-2+3-4+5-6+7....in C++
- How to create 7-Tuple or Septuple in C#?
- Design a DFA accepting a language L having number of zeros in multiples of 3
- Print first m multiples of n in C#
- Finding n-th number made of prime digits (2, 3, 5 and 7) only in C++
- Array of multiples - JavaScript
- Count all possible groups of size 2 or 3 that have sum as multiple of 3 in C++
- How To Use Systemctl On CentOS 7.x or RHEL Linux 7
- Number of Groups of Sizes Two Or Three Divisible By 3 in C++
Advertisements