58.4k views
2 votes
Write a C function to output only item names that their beginQty and endQty is the same. The arguments to the function are the array and the number of elements in the array. Use array notation.

User Clariza
by
5.1k points

1 Answer

2 votes

Answer:

Following are the function to the given question:

void same_quantity_inventory(inventory *arr, int size)//defining a method same_quantity_inventory that takes two parameters

{

inventory *p = arr;//defining a pointer variable that holds array value

while (p < arr + size)//defining while loop that checks pointer value less than arr and its size

{

if (p->endQty == p->beginQty)//use pointer to check array start and end value

printf("name: %s, start quantity: %d, end quantity: %d\\", p->name, p->beginQty, p->endQty);//print value

p++;//incrementing pointer value

}

}

Step-by-step explanation:

In the given code a method "same_quantity_inventory" takes two parameters that are "arr and size". In the next step, a pointer variable "p" is declared that holds the "arr" value. It defines the while loop that checks pointer value less than arr and its size inside the loop and if block is declared that use pointer to check array start and end value, and prints its calculated value.

User Nicky Mattsson
by
5.1k points