- 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

# Count divisors of array multiplication in C++

We are given an array let’s say, arr[] of integer elements of any given size and the task is to calculate the count of the factors of a number calculated by multiplying all the array elements.

Arrays a kind of data structure that can store a fixed-size sequential collection of elements of the same type. An array is used to store a collection of data, but it is often more useful to think of an array as a collection of variables of the same type.

## For example

Input− int arr[] = {2, 3}Output− count is 4

**Explanation** − the multiplication of array is 2 * 3 is 6 and the factors of 6 are 1, 2, 3, 6. So in total there are 4 factors of 6.

Input− int arr[] = {2, 3, 5}Output− count is 8

**Explanation** − the multiplication of array is 2 * 3 * 5 is 30 and the factors of 30 are 1, 2, 3, 5, 6, 10, 15, 30. So in total there are 8 factors of 30.

## Approach used in the below program is as follows

Create an array let’s say, arr[]

Calculate the length of an array using the length() function that will return an integer value as per the elements in an array.

Declare a temporary variable let’s say, temp set it to 1

Start loop for i to 0 and i less than size of array

Set temp to temp * = arr[i]

Call another function that will return a count.

Take a temporary variable that will store the count of elements.

Start loop for i to 1 and i less than equals to mul.

Inside loop, check if temp % i = 0 then increment the value of count by 1.

Return the count

Print the result.

## Example

#include <iostream> using namespace std; // Function to count number of factors int divisors(int N){ // Initialize result with 0 int result = 0; // Increment result for every factor // of the given number N. for (int i = 1; i <= N; ++i){ if (N % i == 0){ result++; } } return result; } int countmultiples(int arr_1[], int size){ // To multiply all elements of // the given array. int temp = 1; for (int i = 0; i < size; ++i){ temp *= arr_1[i]; } return divisors(temp); } // main function int main(){ int arr_1[] = { 5, 10, 15 }; int size = sizeof(arr_1) / sizeof(arr_1[0]); cout <<"count is "<<countmultiples(arr_1, size); return 0; }

## Output

If we run the above code we will get the following output −

count is 16

- Related Questions & Answers
- Count all perfect divisors of a number in C++
- C++ program for multiplication of array elements
- Count the number of common divisors of the given strings in C++
- Find reminder of array multiplication divided by n in C++
- Count total divisors of A or B in a given range in C++
- C Program to Check if count of divisors is even or odd?
- Divisors of n-square that are not divisors of n in C++ Program
- Java program for Multiplication of Array elements.
- Find sum of divisors of all the divisors of a natural number in C++
- C/C++ Program to Find reminder of array multiplication divided by n ?
- Count of divisors having more set bits than quotient on dividing N in C++
- Program to find count of numbers having odd number of divisors in given range in C++
- Closest Divisors in C++
- Four Divisors in C++
- Program to count number of common divisors of two numbers in Python