prime check in c

Solutions on MaxInterview for prime check in c by the best coders in the world

showing results for - "prime check in c"
Francesco
29 Jun 2019
1int isPrime(long long number) {
2
3	if (number == 0 || number == 1 || (number % 2 == 0 && number > 2)) {
4		return 0;
5	}
6
7	else {
8		for (long long i=3; i <= (long long)sqrt(number)+1; i++) {
9			if (number % i == 0) {
10				return 0;
11			}
12		}
13		return 1;
14	}
15}
Justin
09 Feb 2017
1#include <stdio.h>
2int main() {
3    int n, i, flag = 0;
4    printf("Enter a positive integer: ");
5    scanf("%d", &n);
6
7    for (i = 2; i <= n / 2; ++i) {
8
9        // condition for non-prime
10        if (n % i == 0) {
11            flag = 1;
12            break;
13        }
14    }
15
16    if (n == 1) {
17        printf("1 is neither prime nor composite.");
18    }
19    else {
20        if (flag == 0)
21            printf("%d is a prime number.", n);
22        else
23            printf("%d is not a prime number.", n);
24    }
25
26    return 0;
27}
28
queries leading to this page
prime no or composite cryptography program in cto check prime number in c gfgcheck if prime number in ccheck a number is prime or not in cc program to check prime numberprime chec in cc program to check whether a number is prime or not primeprogram for prime number in cprime number or not in cfinding prime number in cc program for prime number using while loopif a number is prime or not in cprime number using do while loop in ccode to find prime numbers in calgorithm for checking prime number in cc program to find prime numberprime number c codecheck if prime in cc program to check whether a number is prime or not using functionc program to check whether a number is prime or notwrite a program to check whether a number is prime or not in clogic to check if a number is prime in cfastest way to check if a number is prime in cprint prime numbers in until certain number in ccode to find prime numberis prime number in ccheck prime in ca program in c for prime number to look at a guess numberfunction to check prime number cc prime number checkchecking prime or not in c programprime number in c codeprime number code logicc code to find prime numberhow to check if number is prime in cdetermine a number is prime in chow to check primei n cc how to calculate prime numberc program to find input number is prime or compositeif condition for prime number in cprime number c programlogic for prime numberc how to find prime numberprogram to find whether a number is prime or notprime number condition in cprime number function in c languagewrite a program to check that given number is prime or not in ccheck prime numbers in c using functioncheck if number is prime codecheck prime number in c using sqrtgenerating prime number in c using for loophow to find prime numbers cchecking if an number is prime or not cprime number display in cc prog for prime numberwrite a c program to print prime numbers with user defined function using do while loopc program to check if number is primecheck whether a number is prime or not in c using functionwap to check if a number is prime or notc check prime numberprime number finding in cfunction for a prime number cwhether the number is prime of not cfastest way to see if a number is prime in cwrite a program in c to find prime numberto check whether a number is prime or not in cfunction to check prime number in ccount prime numbers code in ccheck prime number cprime number using function in cc program to check if a number is prime using bitwise operationsc program for prime numberc program for primelogic of check if number is prime in c language if elsefind prime number in a given number in cbest way to see if a number is prime in cprime digits in a given number in cprint prime number in cc program to check prime or notfind no is prime program in clogic for primehow to find if a number is prime in cwap to check prime number in cfind n prime number through while loop in cprime number formula in cwrite a c program to check its prime number or nothow to find the prime number and input is geting by user in c program using if statementwrite a c program to check whether a number is prime number or not print the prime number series in c program2 write a c program to check prime number prime number check cc program to display the prime numbers below ncheck prime number with even in chelper function check prime number in cprogram to find whether the number is prime or notc program to check for prime numbersc program to find prime numbersprime number check c programcheck prime number in c using different methodsc program to check if a number is primeprime number program using while in cprogram to check given number is prime or not using for loop in cprime number program in cc program to find prime number using function knowprogramhow to check if a number is prime in cc code for prime numberwrite a c program to whether a number is prime or not write a c program to check whether a number is prime or not how to find prime numbers in cprime numbers codecheck whether a number is prime or not in chow to find the prime number and input is geting by user in c program using if statement without using for loopc code for prime numbers geeksprime number code in cprime number program in c without using loop programizcheck prime number in c using while loopprime number program in data structureprime no in ccheck given number is prime or not in cprogram to find prime number in a range chow to find out prime numbers in cfinding prime no in c without using loopfind prime numbers in cprogram to check whether a number is prime in cis given no prime no program in ccheck prime number in chow to find if a number is prime or not in cprime chec kin cfind prime number algorithm ccheck prime number in c functionc check primeisprim in cc program to determine prime numberwrite a c program to find out if a number is a e2 80 9cprime number e2 80 9dc program to check for prime numbercode to print prime numbers in cprime number function c c programme that search prime numberprogram of prime number in cprime numbers in cprogram to check if number is prime in c prime number program using while loop in cc program to find a prime numbercheck if a number is prime ccheck if number is prime c formula for prime numbers in cc programming prime numberc program to check whether a number is prime or not prime number with if elsehow to check is number is prime in cc program to find whether a number is prime or notchecking prime number in ccheck number is prime or not in cvalid primes function in cc program to find primeprime number c program using functionprime number till given number in cwrite a c program to find whether a given number is prime number or notwrite a c program to check prime numberprime number check in cc programme check the number is prime number or not do while loopc program to check whether a number is prime number or not find a prime number in cc program to check whether an integer is prime or not in o 281 29c program for prime numbersc program to check prime number using functionc check for prime numberchek if a number is prime in ccheck the prime number in cfind if is prime cto find prime or not in calgorithm wap to check whether the entered number is a prime number using while loop in ceasiest way to check if a number is prime in cc is prime numberhow to find the prime numbers in cwrite a program to determine if a number is a prime number in c languagehow to know if number is prime cprime number using while loop in cc program to check prime number without using loopprime no check cprogram in c to find prime number using functionc program to find the prime numbersprogram to find prime number in a range ccheck whether the given number is prime or not in cc program to check whether an integer is prime or notc program that prints prime numbershow to find prime number in cc program to find if a number is prime or notc program to check prime number without using loop in cprime check in cprime number in c programmingfind all the prime number before a user given number in cwrite a c program to print whether the given number is prime or notprogram in c to check if a number is primeprint if a number is prime in cdetermining if a number is prime in cprime or not in chow to check a number is prime or not in cc prime number functionc program prime numberlogic for prime number in cprime number logic in chow to check for a prime number in ccheck if prime function in cc program to find prime or notprime no program in chow to find prime or not in chow to compute prime number in cfunction is prime cc code prime numbercheck for prime number in chow to check weather a number is prime or not cfind prime number in cwrite a c program to check whether a number is prime number or not using loopc program to see if a number is primesee if number is prime chow to check if a number is a prime number in chow to check prime number in clogic to find prime number in chow to find a prime number in c programc check if number is primeprime check in c