diff --git a/C&C++/manya mangla/day1_dsa_ques2.c b/C&C++/manya mangla/day1_dsa_ques2.c new file mode 100644 index 00000000..2307a0f7 --- /dev/null +++ b/C&C++/manya mangla/day1_dsa_ques2.c @@ -0,0 +1,28 @@ +#include + +int countPairs(int arr[], int n, int k) { + int count = 0; + + // Iterate through each pair (i, j) where i < j + for (int i = 0; i < n; i++) { + for (int j = i + 1; j < n; j++) { + // Check if the sum of arr[i] and arr[j] is divisible by k + if ((arr[i] + arr[j]) % k == 0) { + count++; + } + } + } + + return count; +} + +int main() { + int arr[] = {1, 3, 2, 6, 1, 2}; + int k = 3; + int n = sizeof(arr) / sizeof(arr[0]); + + int result = countPairs(arr, n, k); + printf("%d\n", result); // Output: 5 + + return 0; +}