Untitled

mail@pastecode.io avatar
unknown
c_cpp
2 months ago
690 B
3
Indexable
Never
#include <stdio.h>

int is_prime(int x)
{
    if (x < 2) return 0;
    for (int i = 2; i <= x / 2; i++) {
        if (x % i == 0) return 0;
    }
    return 1;
}

int palin(int x)
{
    int temp = x, rev = 0;
    while (temp != 0) {
        rev = ((rev * 10) + (temp % 10));
        temp /= 10;
    }

    if (x == rev) return 1;
    else return 0;
}

int vecna(int x)
{
    if (is_prime(x) && palin(x)) {
        return 1;
    }
    else {
        return 0;
    }
}

int main()
{
    int a, b;
    scanf("%d %d", &a, &b);

    for (int i = a; i <= b; i++) {
        if (vecna(i)) {
            printf("%d ", i);
        }
    }

    return 0;
}
Leave a Comment