C Program to Check Whether a Given Number is Prime Number or Not

#include<stdio.h>
#include<conio.h>

int main()
{
	 int number, i, flag=0;
	 clrscr();
	 
	 // Inputs
	 printf("Enter integer number: ");
	 scanf("%d", &number);
	 
	 // Checking for prime
	 for(i=2;i<=number/2; i++)
	 {
		  if(number%i==0)
		  {
			   flag = 1;
			   break;
		  }
	 }
	 
	 // Taking decision
	 if(flag==0 && number>=2)
	 {
	  	printf("%d is PRIME.", number);
	 }
	 else
	 {
	  	printf("%d is NOT PRIME.", number);
	 }
	
	 getch();
	 return(0);
}

Output 

Run 1:
-----------
Enter integer number: 13 ↲
13 is PRIME.

Run 2:
-----------
Enter integer number: 16 ↲
16 is NOT PRIME.

Run 3:
-----------
Enter integer number: 1 ↲
1 is NOT PRIME.

Run 4:
-----------
Enter integer number: 2 ↲
2 is PRIME.

Leave a Reply

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

https://atozonlinesolutions.com/wp-content/uploads/2017/03/logo_white.png
https://atozonlinesolutions.com/wp-content/uploads/2017/03/logo_white.png
About
Products
Subscribe

If you wish to receive our latest news in your email box, just subscribe to our newsletter. We won’t spam you, we promise!

    Applauz

    As the pioneer of the lean startup movement, APPLAUZ has dedicated it’s time to sharing effective business strategies that help new businesses and enterpreneurs put their money to work in the right way.

    Subscribe

    If you wish to receive our latest news in your email box, just subscribe to our newsletter. We won’t spam you, we promise!

      Applauz

      As the pioneer of the lean startup movement, APPLAUZ has dedicated it’s time to sharing effective business strategies that help new businesses and enterpreneurs put their money to work in the right way.

      Copyright by BOLD THEMES. All rights reserved.