Answers for "c program to check prime number"

C
4

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

prime numbers in c

#include<stdio.h>
main() {
    int n, i, count=0;
    printf("Enter Number");
    scanf("%d",&n);
   
    for ( i = 1; i<= n; i++) {
        if (n % i == 1) {
            count++;
        }
    }
    if( count == 2) {
        printf("Prime Number");
    }
    else {
        printf("Not A  Prime Number");
    }
}
Posted by: Guest on May-18-2021
1

c program to check prime number using for loop

#include <stdio.h>
int main() {
    int n, i, flag = 0;
    printf("Enter a positive integer: ");
    scanf("%d", &n);

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

        // condition for non-prime
        if (n % i == 0) {
            flag = 1;
            break;
        }
    }

    if (n == 1) {
        printf("1 is neither prime nor composite.");
    }
    else {
        if (flag == 0)
            printf("%d is a prime number.", n);
        else
            printf("%d is not a prime number.", n);
    }

    return 0;
}
Posted by: Guest on December-14-2020
1

prime number c program

int isPrime(int n) {
  for (int i = 2; i < n; i++) if (n % i == 0) return 0; 
  return 1;
}
Posted by: Guest on March-25-2021
0

c program to check prime number

//program to find prime number or not using c programming
#include<stdio.h>
#include<conio.h>
// program starts from here after main() function
    void main(){
    int n; 
    int i,count =0;
    // count is incremented when the loop is true.
    printf("Enter the number\n");
    scanf("%d",&n);
    for (i=1; i<=n; i++){
        if(n%i==0){
            count++;
        }
    }
     // for the prime number the no of count is 2
     // number is divided by 1 or itself(given number) so count ==2
        if(count ==2){
            printf("%d is prime number.\n",n);
        }
        
    // for the composite number the number is divided by more than 2 number.
    else{
         printf("%d is not prime number\n",n);
    }

    getch();
    }
Posted by: Guest on October-01-2021
0

c program to check prime number

//program to find prime number or not using c programming
#include<stdio.h>
#include<conio.h>
    void main(){
    int n; 
    int prime=1;
    printf("Enter the number\n");
    scanf("%d",&n);
    for (int i= 2; i<n; i++){
        if(n%i==0){
            prime=0;
            break;
        }
    }
        if(prime==0 ){
            printf(" %d is not prime number.\n",n);
        }
    else{
         printf(" %d is prime number\n",n);
    }

    getch();
    }
Posted by: Guest on October-01-2021

Code answers related to "c program to check prime number"

Code answers related to "C"

Browse Popular Code Answers by Language