Dsa
Math
Easy
Cumulative Average Calculator
Write a program that reads a sequence of integers and prints the cumulative average after each new integer. The program should stop reading input when a negative integer is entered.
Input:
A sequence of integers (multiple lines), ending with a negative integer.
Output:
Print the cumulative average after each input integer (excluding the negative integer).
Example:
Input:
10
20
30
-1
Output:
10.0
15.0
20.0
Key concepts
averagecumulativeiteration
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now