159k views
2 votes
Assume that Precinct Report is a structured type with these fields,address (a string),and three int fields which are counts of crimes in the given precinct: felonies, murders, and robberies. Assume that N PRECINCTS is a pre-declared int constant and that an array named all Precincts with N PRECINCTS elements, each of type Precinct Report has been declared and initialized Assume that an int variable murder Count has been declared. Write the necessary code that traverses the all Precincts array and adds up all the murder counts storing the resulting total in murder Count.

User Cjohns
by
5.4k points

1 Answer

2 votes

Answer:

Following are the code in the C Programming Language:

/*-----code is here-------*/

murderCount=0; //set count of murder to 0

for (int i=0; i<NPRECINCTS;i++) //set for loop

murderCount += allPrecincts[i].murders; //traverse the precincts to murder

Step-by-step explanation:

In the following code, we use structure through C Programming Language in which we write the following code of structure.

  • Firstly, we set the integer data type variable "murderCount" and assign the value 0.
  • Then, we set the for loop in which we traverse all the array type variable "allPrecincts" then, add to the variable "murderCount".
User Dita
by
6.3k points