25.2k views
11 votes
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.

1 Answer

12 votes

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

}

Step-by-step 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.

User Traxo
by
3.4k points