Answers for "c code to check if a number is prime or not"

C
7

prime check in c

int isPrime(long long number) {

	if (number == 0 || number == 1 || (number % 2 == 0 && number > 2)) {
		return 0;
	}

	else {
		for (long long i=3; i <= (long long)sqrt(number)+1; i++) {
			if (number % i == 0) {
				return 0;
			}
		}
		return 1;
	}
}
Posted by: Guest on February-07-2021
0

check if the number is prime in c

#include <stdio.h>

void main() {
    int number;

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

    if (number == 0 || number == 1 || (number % 2 == 0 && number > 2))
    {
        printf("\n\tThe entered number is not a prime number!");
    }
    else
    {
        printf("\n\tThe entered number is a prime number!");
    }
}
Posted by: Guest on March-18-2022

Code answers related to "c code to check if a number is prime or not"

Code answers related to "C"

Browse Popular Code Answers by Language