Write a function that accepts two pointers; one to the first element and one to the last element of an integer array. The function returns how many numbers are negative in the array. Use only pointer notation.

Respuesta :

Answer:

The code to this question can be defined as follows:

int count(int *first, int *last)//defining a method count that accepts two integer pointer    

{

   int c=0;//defining integer variable c

   while (first <= last)//defining a while loop that counts first to last value  

   {

       if (*first < 0)//use if block to check negative value

           c++;//increment variable value

       first++;//increment first parameter value

   }

   return c;//return c value

}

Explanation:

In this code, a method "count" is declared that accepts two pointer variable "first and last" as the parameter, inside the method an integer variable "c", and a while loop is declared that counts values, and inside this an if block is used that counts the negative value and increment its value, and also increments the first parameter value, and return c value.      

ACCESS MORE
ACCESS MORE
ACCESS MORE
ACCESS MORE