This project is a computational tool written in C designed to analyze a specific range of integers and determine the density of prime numbers within that interval.
A Prime Number is a natural number greater than 1 that has no positive divisors other than 1 and itself. In cryptography and number theory, understanding the distribution of primes within specific intervals is a fundamental concept.
This algorithm solves the counting problem:
The program executes the following logic:
- Input Parsing: Accepts two integer bounds (Start/End) from the user.
- Interval Normalization: Automatically detects which input is the lower bound and which is the upper bound.
- Iterative Validation: Loops through every integer in the range.
-
Primality Test: Uses trial division (checking divisibility from 2 to
$n/2$ ) to verify if a number is prime. - Accumulation: Increments a counter for each verified prime found.
- Compile the code:
gcc main.c -o prime_counter
- Run the executable:
./prime_counter
- Enter two numbers (e.g.,
10and50) to see how many prime numbers exist between them.
This repository demonstrates nested loop logic and conditional algorithmic optimization in C.