This project implements a data processing algorithm in C that analyzes a stream of integers provided by the user. It functions as a Conditional Filter that aggregates statistics based on the magnitude (number of digits) of the input.
The system uses a Sentinel-Controlled Loop structure, meaning the iteration count is not fixed but determined by the data itself.
- Input Stream: Continuously accepts integers from the standard input.
-
Termination Condition: Checks every input for the sentinel value (
-1). If found, the data stream is considered closed. -
Magnitude Analysis:
- Decomposes the integer using iterative division (
/ 10). - Calculates the digit count:
$d = \lfloor \log_{10}|x| \rfloor + 1$ .
- Decomposes the integer using iterative division (
-
Filtering & Aggregation:
-
Filter:
if (digits == 2) - Action: Increment the global counter.
-
Filter:
This logic is fundamental in systems where the amount of data is unknown beforehand (e.g., reading sensor data until a stop signal).
- Compile the code:
gcc main.c -o data_filter
- Run the executable:
./data_filter
- Enter various numbers. To stop the analysis and see the count of 2-digit numbers, enter
-1.
This repository demonstrates while-loops, sentinel logic, and numerical analysis in C.