C Program to check prime number

A prime number is a number which is only divisible by 1 and the number itself. This is an easy C program to know whether a number is prime or not.

#include<stdio.h>
int main(){
int n,flag,i;
printf("enter the number to check");
scanf("%d",&n);
if(n<=1){
printf("not prime");
exit(1);
}

flag=0;

for(i=2;i<=n/2;i++){
if(n%i==0){
flag=1;
break;
}
}
if(flag==0)
printf("prime number");
if(flag==1)
printf("not a prime number");
return 0;
}

 

Output