C Program to Display Prime Numbers Between Two Intervals Using Functions - Source Code, Output & Execution Flow

C Program to Display Prime Numbers Between Two Intervals Using Functions

This C program displays prime numbers in a range using a reusable prime-checking function.

#include <stdio.h>
int isPrime(int n) {
    int i;
    if (n <= 1) return 0;
    for (i = 2; i * i <= n; i++) if (n % i == 0) return 0;
    return 1;
}
int main() {
    int low, high, i;
    printf("Enter two intervals: ");
    scanf("%d %d", &low, &high);
    printf("Prime numbers: ");
    for (i = low; i <= high; i++) if (isPrime(i)) printf("%d ", i);
    printf("
");
    return 0;
}
Enter two intervals: 10 30
Prime numbers: 11 13 17 19 23 29

In this program, the input is read first when required, the core logic is applied step by step, and the final result is displayed using printf(). Follow the execution flow beside the code to understand how each statement contributes to the output.