C Program to Check Whether a Number is Prime or Not

C program to Check Whether a Number is Prime or Not:

Here I shared the C program to Check Whether a Number is Prime or Not using Loop and if-else statement.

For example, if the user enters 23 then the output will be:

23 is a prime number



#include<stdio.h>
int main()
{            
   int n,i,flag=0;
  printf("\n Enter the number:");
  scanf("%d",&n);
    for(i=2;i<=n-1;i++)
   {
    if(n%i==0)
    {
     flag=1;
     break;
  }
   }
   if(flag==0)
     {
     printf("\n %d is prime number",n);
     }
   else
     {
      printf("\n %d is not prime number",n); 
     }
 return 0;
}


NOTE: You have any problem in the above C Program to Check Whether a Number is Prime or Not and does not hesitate and write your problem in the comment box. I will support your problem.

If you have any doubts, Please let me know

Previous Post Next Post

Contact Form