This project implements a statistical algorithm in C designed to process a stream of integers. It acts as a Selective Filter that ignores non-positive values and computes the arithmetic mean of the valid dataset upon termination.
The program processes input
Upon receiving the Sentinel Value (
Where:
-
$S$ : The filtered array of positive integers. -
$n$ : The total count of valid positive entries (index). -
$\mu$ : The calculated arithmetic mean.
- Stream Processing: Uses an infinite loop structure to accept dynamic input length.
- Sentinel Termination: Stops execution gracefully when
-1is detected. - Data Filtering: Automatically discards negative numbers and zero from the calculation set.
- Error Handling: Includes a check to prevent Division by Zero errors if no valid numbers are entered.
- Compile the code:
gcc main.c -o mean_calc
- Run the executable:
./mean_calc
- Enter integers (e.g.,
10,-5,20,0,30). - Enter
-1to finish and view the average of positive inputs (10, 20, 30-> Average:20.00).
This repository demonstrates array buffering and sentinel-controlled loops in C.