
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
Find a number that divides maximum array elements in C++
In this tutorial, we are going to find the number that is divided into maximum elements in the given array.
Let's see the steps to solve the problem.
Initialize the array and a variable to store the result.
Iterate over the array.
Initialize the counter variable.
Iterate over the array again.
Increment the counter if the current element is divisible by the array element.
Update the result if the current count is maximum.
Print the result.
Example
Let's see the code.
#include <bits/stdc++.h> using namespace std; int numberWithMaximumMultiples(int arr[], int n) { int result = -1; for (int i = 0; i < n; i++) { int count = 0; for (int j = 0; j < n; j++) { if (arr[i] % arr[j] == 0) { count++; } } if (count > result) { result = count; } } return result; } int main() { int arr[] = {4, 24, 16, 3, 12, 28}; cout << numberWithMaximumMultiples(arr, 6) << endl; return 0; }
Output
If you execute the above code, then you will get the following result.
4
Conclusion
If you have any queries in the tutorial, mention them in the comment section.
- Related Articles
- Find integers that divides maximum number of elements of the array in C++
- Find maximum power of a number that divides a factorial in C++
- Find the greatest number that exactly divides 289 and 391.
- Find prime number K in an array such that (A[i] % K) is maximum in C++
- Find the largest number that divides 280 and 490 without leaving a remainder.
- Find Two Array Elements Having Maximum Product in Java?
- Find Two Array Elements Having Maximum Sum in Java?
- Maximum number of contiguous array elements with same number of set bits in C++
- Find Number of Array Elements Smaller than a Given Number in Java
- Find k maximum elements of array in original order in C++
- Maximum value K such that array has at-least K elements that are >= K in C++
- Find document that matches same array elements in MongoDB?
- Maximum sum in circular array such that no two elements are adjacent in C++
- Find maximum number that can be formed using digits of a given number in C++
- Recursive Programs to find Minimum and Maximum elements of array in C++

Advertisements