Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
535 B
0
Indexable
Never
#include <stdio.h>
#include <math.h>

int isPrime(int n) {
    if (n < 2)
        return 0;

    for (int i = 2; i  <= sqrt(n); i++) 
    {
        if (n % i == 0)
            return 0;
    }

    return 1;
}

void printPrime(int a, int b) 
{
    printf("Cac so nguyen to tu %d den %d la: ", a, b);
    for (int i = a; i <= b; i++) 
    {
        if (isPrime(i))
            printf("%d ", i);
    }
}

int main() {
    int a, b;

    printf("Nhap vao khoang a, b: ");
    scanf("%d %d", &a, &b);

    printPrime(a, b);

    return 0;
}