check prime number or not c

[ad_1]

prime check in c
int isPrime(long long number) {

	if (number == 0 || number == 1 || (number
		return 0;
	}

	else {
		for (long long i=3; i <= (long long)sqrt(number)+1; i++) {
			if (number
				return 0;
			}
		}
		return 1;
	}
}
Prime Number Check Program in C
#include 

main() {
  int n, i, c = 0;
  printf("Enter any number n:");
  scanf(

  //logic
  for (i = 1; i <= n; i++) {
      if (n
         c++;
      }
  }

  if (c == 2) {
  printf("n is a Prime number");
  }
  else {
  printf("n is not a Prime number");
  }
  return 0;
}
Program Output:
check prime number or not c
#include 

int main() {

  int n, i, flag = 0;
  printf("Enter a positive integer: ");
  scanf(


  if (n == 0 || n == 1)
    flag = 1;

  for (i = 2; i <= n / 2; ++i) {


    if (n
      flag = 1;
      break;
    }
  }

  // flag is 0 for prime numbers
  if (flag == 0)
    printf(
  else
    printf(

  return 0;
}
check if the number is prime in c
#include 

void main() {
    int number;

    printf("\n\n\tEnter the number and we will check, if the number is prime or not : ");
    scanf(

    if (number == 0 || number == 1 || (number
    {
        printf("\n\tThe entered number is not a prime number!");
    }
    else
    {
        printf("\n\tThe entered number is a prime number!");
    }
}

[ad_2]

Please follow and like us:
Content Protection by DMCA.com