Skip to content

Commit 8b74624

Browse files
authored
creatred file for count divisible
1 parent bd867fc commit 8b74624

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

count-divisible.cpp

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
// CPP program to count divisible pairs.
3+
#include <iostream>
4+
using namespace std;
5+
6+
int countDivisibles(int arr[], int n)
7+
{
8+
int res = 0;
9+
10+
// Iterate through all pairs
11+
for (int i=0; i<n; i++)
12+
for (int j=i+1; j<n; j++)
13+
14+
// Increment count if one divides
15+
// other
16+
if (arr[i] % arr[j] == 0 ||
17+
arr[j] % arr[i] == 0)
18+
res++;
19+
20+
return res;
21+
}
22+
23+
int main()
24+
{
25+
int a[] = {1, 2, 3, 9};
26+
int n = sizeof(a) / sizeof(a[0]);
27+
cout << countDivisibles(a, n);
28+
return 0;
29+
}

0 commit comments

Comments
 (0)