C program to check whether a number is prime or not.

 

01 #include<stdio.h>
02
03 int main()
04 {
05 int i,j=2,ch=0;
06
07 printf("nENTER ANY NUMBER ");
08 scanf("%d",&i);
09 while(j<=i/2)
10 {
11 if(i%j==0)
12 {
13 printf("%d IS NOT PRIME",i);
14 ch=1;
15 break;
16 }
17 else
18 {
19 j++;
20 }
21 }
22 if(ch==0)
23 {
24 printf("%d IS PRIME",i);
25 }
26 }
 
OUTPUT :

(1st Run)

ENTER ANY NUMBER 5
5 IS PRIME

(2nd Run)

ENTER ANY NUMBER 6
6 IS NOT PRIME

Related Post

Leave a Reply

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


The reCAPTCHA verification period has expired. Please reload the page.