C Exercises: Compute the average value of the elements in a queue
8. Queue Average Value
Write a C program to compute the average value of the elements in a queue.
Sample Solution:
C Code:
Output:
Queue elements are: 1 2 3 4 5 Average of the elements in the queue is: 3.000000 Remove 2 elements from the said queue: Queue elements are: 3 4 5 Average of the elements in the queue is: 4.000000 Insert 3 more elements: Queue elements are: 3 4 5 300 427 519 Average of the elements in the queue is: 209.666672
Flowchart
For more Practice: Solve these Related Problems:
- Write a C program to implement a queue that calculates the average value in constant time using auxiliary variables.
- Write a C program to compute the average only for even numbers in an array-based queue.
- Write a C program to implement a sliding window average on a queue as elements are enqueued and dequeued.
- Write a C program to implement a linked list queue that computes the average and rounds it to the nearest integer.
C Programming Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Calculate the sum of the elements in a queue.
Next: Find the maximum element in a queue.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.