5+ C Prime Number Checker Program Examples

This post contains a total of 5+ Hand-Picked C Prime number checker Program Examples with Source Code. All these prime number checker programs are made using C Programming Language.

You can use the source code of these examples with credits to the original owner.

Related Posts

C Prime Number Checker Programs

1. By suman Dhakal

Made by suman Dhakal. Simple C Program to check if an entered number is prime. Source

3
it is a prime number
#include <stdio.h>
void main(){int a,j;scanf("%d",&a);

for(j=2;j<a;j++){ if(a%j==0)break;}

if(j==a)printf("it is a prime number");

else printf("it is not a prime number");}

2. By Prasanth Naidu Karaka

Made by Prasanth Naidu Karaka. Source

entered number is : 10 
it is not a prime number
#include <stdio.h>
int main() {
    int x,y,z=0;
    scanf("%d",&x);
    printf ("entered number is : %d \n",x);
    if(x<0){
        printf("please enter a positive integer");
    }
    if(x==1){
        printf ("it is neither prime number nor a composite number");
        
    }
    if(x>1){
    for( y=2;y<x;y++){
        if(x%y==0){
            printf ("it is not a prime number");
            z++;
            break;
            
        }
        
    }
    
   if(z==0){
            printf ("it is a prime number");
        }}
    printf ("\n\n\n\n")  ;  
    printf ("please upvote if you like");
    return 0;
}

3. By Akshat Vyas

Made by Akshat Vyas. Entering a positive number will give you the output whether the number is prime or not. Source

Enter a positive integer: 10
10 is not a prime number.
#include <stdio.h>

int main() {

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

  // 0 and 1 are not prime numbers
  // change flag to 1 for non-prime number
  if (n == 0 || n == 1)
    flag = 1;

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

    // if n is divisible by i, then n is not prime
    // change flag to 1 for non-prime number
    if (n % i == 0) {
      flag = 1;
      break;
    }
  }

  // flag is 0 for prime numbers
  if (flag == 0)
    printf("%d is a prime number.", n);
  else
    printf("%d is not a prime number.", n);
  printf("\nUpvote if you like ๐Ÿฅฐ");
  return 0;
}

4. By Nossair el Katouri

Made by Nossair el Katouri. Source

15
15 : Not a prime number
#include<stdio.h>
int main()
{
    int N,i,j,m,x;float r;
    scanf("%d",&N);
    r=1;
    for(i=1;i<=100;i++)
    {
        r=(r/2)+(N/(2*r));
    }
    m=r;
    m=m+1;
    x=0;
    for(j=2;j<=m;j++)
    {
        if(N%j>0)
        {
           x=x*1;
        }
        else 
        {
            x=x+1;
        }
    }
    if(x>0)
    {
        printf("%d : Not a prime number",N);
    }
    else 
    {
        printf("%d : is a prime number",N);
    }
    
}

5. By Charan Leo

Made by Charan Leo. Source

enter any no3-3 
:3
prime no
#include <stdio.h>

int main() {
int c=2,no;
printf ("enter any no");
scanf("%d",&no);

while(no%c!=0)
{
    c++;
    printf("%d-%d \n",no,c);
}
if(no==c)
{
    printf (":%d\nprime no",no);
}
else
{
    printf (":%d\nNot prime",no);
}
    return 0;
}

6. By Sharon Shelton

Made by Sharon Shelton. Basic Prime Number Checker program using C. Source

Enter the number to be checked:12
12 is not a prime number
#include <stdio.h>

int main() {
    int n,i,count=0;
    printf("Enter the number to be checked:");
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
       if(n%i==0)
            count++;
    }
    if(count==2)
        printf("%d is a prime number",n);
    else
        printf("%d is not a prime number",n);
    return 0;
}