This project implements a numerical search and filter algorithm in C. It generates a specific sequence of integers based on modular arithmetic constraints and employs a Reverse Output Strategy to present the data in descending order without the computational cost of a sorting algorithm.
The algorithm searches for a set of integers
-
Threshold:
$x > 10$ -
Odd Parity:
$x \equiv 1 \pmod 2$ (Odd Number) -
Divisibility:
$x \equiv 0 \pmod 3$ (Multiple of 3)
The resulting sequence (found in ascending order) is:
-
Search Loop: Iterates starting from 11 (
$x=11 \dots \infty$ ). -
Filtering: Applies nested
ifconditions to validate constraints. -
Storage: Valid numbers are stored in a fixed-size array (
buffer[5]). -
Reverse Rendering (Optimization):
- Instead of running a sorting algorithm (like Bubble Sort) which costs
$O(n^2)$ , the program takes advantage of the fact that data is discovered in ascending order. - It iterates the array backwards (Index
$4 \to 0$ ) to print the result "Largest to Smallest". -
Time Complexity:
$O(n)$ (Linear scan).
- Instead of running a sorting algorithm (like Bubble Sort) which costs
- Compile the code:
gcc main.c -o sequence_filter
- Run the executable:
./sequence_filter
- Output:
39 33 27 21 15
This repository demonstrates conditional logic, array manipulation, and algorithmic efficiency in C.