Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Consider that a system tracks what the time is when some external event occurs (

ID: 3781088 • Letter: C

Question

Consider that a system tracks what the time is when some external event occurs (such as a user pressing a button, a person enters a room or similar) in an array. The system simply started counting seconds when the power was turned on, so if the first event occurred 290 seconds after the power was turned on, the entry in events[0] would be 290. Let there be a variable called numEvents that indicates how many values are in the events[] array.

Using C (or a similar language), write code to calculate the average delay between events.

Explanation / Answer

let's call the function which will give average delay between events as avgDelay().

avgDelay(int *events, numEvents)

{

int count=0, delay =0; /*count will calculate number of events and delay will calculate the total delay between events*/

for(int i=0; i<numEvents; i++)

{

delay+=events[i+1]-events[i]; //Total delay between event is calculated here

count++;

}

int average_delay=delay/count; // This is average delay between events

return average_delay;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote