C Program - Display Prime Numbers Between Two Intervals Using Functions

#include <stdio.h>

int isPrime(int num) {
    if(num <= 1)
        return 0;
    for(int i = 2; i < num; i++) {
        if(num % i == 0)
            return 0;
    }
    return 1;
}

int main() {
    int start, end;

    printf("Enter two numbers (intervals): ");
    scanf("%d %d", &start, &end);

    printf("Prime numbers between %d and %d:\n", start, end);
    for(int i = start; i <= end; i++) {
        if(isPrime(i))
            printf("%d ", i);
    }

    return 0;
}
Enter two numbers (intervals): 10 20
Prime numbers between 10 and 20:
11 13 17 19

Comments

💬 Please keep your comment relevant and respectful. Avoid spamming, offensive language, or posting promotional/backlink content.
All comments are subject to moderation before being published.


Loading comments...