Write a C++ function
int findQuotient(int arr[], int size, int n)
{
// Write your code here
return -1;
}
Count pairs with quotient equal to "n" In this coding exercise, you are asked to write the body of a function called findQuotient, which takes an integer array with distinct values arr, size of array size, and number n. Your task is to count the number of pairs (a,b) with quotient equal to n, and these two numbers should be perfectly divisible, i.e., dividing number a by b results in number n and remainder .
Sample inputs/outputs Below are some examples: arr[] {2} {1,2,3,4,5,6} {33, 66, 20, 99, 70, 43, 11, 27, 9, 3} {10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150} size 1 6 10 15 n 1 2 3 5 Output 0 3 3
For example, if an array called arr and integer n contains the following values: int arr[] = {1,2,3,4,5,6}; size = 6; n = 2; Then the call findQuotient(arr[], size, n) should return 3. Since there will be three pairs (1,2), 2,4), (3,6) where both a and b are perfectly divisible and returns 2 in the quotient. Note: 1. will not be the part of input array. 2. All the elements of an array will be distinct.
Write a C++ function int findQuotient(int arr[], int size, int n) { // Write your code here return -1; }
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am