We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent bd867fc commit 8b74624Copy full SHA for 8b74624
count-divisible.cpp
@@ -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