PRIME NUMBER IN C LANGUAGE IS OR NOT
#include<conio.h>
#include<iostream>
#include<stdio.h>
int main(){
int n,m,flag=0;
printf("\n Enter the number to know is it prime or not ");
scanf("%d",&n);
m=n/2;
if(n==0||n==1){
printf("\nNot a prime number ");
exit(0);
}
else{
for(int i=2; i<=m; i++){
if(n%i==0){
printf("\n Not a prime number ");
flag=1;
break;
}
}
}
if(flag==0){
printf("\n Number is prime ");
}
return 0;
}
Comments
Post a Comment