C Program to Check Whether Number is Prime or Not

Hello reader! Do you know one thing? Using this article, We can execute the script of “C Program to Check Whether Number is Prime or Not”. Let’s start an article to see the possibilities below.

C Program to Check Whether Number is Prime or Not

C Program to Check Whether Number is Prime or Not

Source Code

#include<stdio.h>
int main()
{
  int n, c;

  printf("Enter a number to check if it's primen");
  scanf("%d", &n);

  for (c = 2; c <= n/2; c++)
  {
    if (n%c == 0)
    {
      printf("%d is a composite number.n", n);
      break;
    }
  }

  if (c == n/2 + 1)
    printf("%d is prime.n", n);

  return 0;
}

Final Words

I hope this article helps you to know about “C Program to Check Whether Number is Prime or Not”. If you face any issues please let me know via the comment section. Share this article with other C/C++ developers via social networks.

Share on:

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Comment