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


In this program, You will learn how to check the 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 the square root of a number is prime or not in c

#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("Number 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