Answers for "to check a prime number in c using count"

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
1

prime number in c

#include<stdio.h>
void main(){
    int num, i;
    int cp = 1;
    printf("Enter a number = ");
    scanf("%d",&num);

    if(num > 0){
        for(i = 2; i < num; i++){
            if(num % i == 0){
                cp = 0;
            }
        }
        if(cp == 1){
            printf("%d is a prime number.", num);
        }
        else{
            printf("%d isn't a prime number.", num);
        }
    }
}
Posted by: Guest on February-24-2022

Code answers related to "C"

Browse Popular Code Answers by Language