check the number is prime or not – C Program

Prime or Not – C Program

Write a c program for check the inputted number is prime or not.

The prime number is divisible only by itself, and the rest of all numbers are composite.

Here is the c program for check the given number is prime or not using for loop.

#include<stdio.h>
#include<conio.h>
 
void main()
{
   int n, a = 2;
 
   printf("Enter the number for check prime or not : \n");
   scanf("%d",&n);
 
   for (a = 2 ; a <= n - 1 ; a++)
   {
      if (n%a == 0)
      {
         printf("The number %d is not prime.\n", n);
	 break;
      }
   }
   if (a == n)
     {
       printf("The number %d is prime.\n", n);
     }
}

The out put of check prime number c program is :

Enter the number for check prime or not :
100
The number 100 is not prime.

//////////

Enter the number for check prime or not :
11
The number 11 is prime.

 

Author: Meera Academy

Leave a Reply

Your email address will not be published. Required fields are marked *