Write a method called countInRange that accepts an array of

Write a method called countInRange that accepts an array of integers, a minimum value, and a maximum value as parameters and returns the count of how many elements from the array fall between the minimum and maximum (inclusive). For example, in the array {14, I, 22, 17, 36, 7, -43, 5}, for minimum value 4 and maximum value 17, there are four elements whose values fall between 4 and 17.

Solution

int countInRange(int arr[50],int min,int max) \\\\ declaration of function with paramaters
{
   int i,count=0; \\\\ count is initialized to 0
   for(i=0;i<50;i++) \\\\ for loop for comparing each element
   {
       if(arr[i]>=min && arr[i]<max) \\\\ condition to check whether the integer is in given range
       count++; \\\\ if ture then count is increased by 1 }
   printf(\"%d\",count); \\\\ count is printed
   return count;\\\\ count is returned to the main method.
}

 Write a method called countInRange that accepts an array of integers, a minimum value, and a maximum value as parameters and returns the count of how many elem

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site