C Program to check square root of a number is prime or not


In this program, You will learn how to check square root of a number is prime or not in c.


Some list of prime numbers is : 2, 3, 5, 7, 11


Example: How to check square root of a number is prime or not in c

Run it Now
#include<stdio.h>
#include<math.h>

int main() {

    int x, y = 1, z, i;
    float f;
    printf("Enter a Number :");
    scanf("%d", &x);

    z = f =  sqrt(x);
    printf("\nNumber Square Root is %f", f);

    for (i = 2; i < z; i++) {
        if (z % i == 0) {
            y = 0;
            break;
        }
    }

    if (y == 1) {
        printf("\nNumber is Prime :%d", z);
    } else {
        printf("\nNumber is Not Prime :%d", z);
    }

    return 0;
}

Output:

Enter a Number :16
Number Square Root is 4.000000
Number is Not Prime :4