

- 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
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 Questions & Answers
- 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++
- Minimum value that divides one number and divisible by other in C++
- Find prime number K in an array such that (A[i] % K) is maximum in C++
- Find document that matches same array elements in MongoDB?
- Find maximum number that can be formed using digits of a given number in C++
- Find a distinct pair (x, y) in given range such that x divides y in C++
- Find array elements that are out of order in JavaScript
- Find k maximum elements of array in original order in C++
- Maximum number of contiguous array elements with same number of set bits in C++
- Maximum value K such that array has at-least K elements that are >= K in C++
- Maximum sum in circular array such that no two elements are adjacent in C++
- Maximum difference elements that can added to a set in C++
- Find maximum number of elements such that their absolute difference is less than or equal to 1 in C++
- Recursive Programs to find Minimum and Maximum elements of array in C++
Advertisements