Prime number in perl - Coder's point

Sunday, June 9, 2019

Prime number in perl

 
#!/usr/local/bin/perl print "Enter a number : "; $num = <>; for($i=2;$i<=$num-1;$i++) { if($num%$i==0) { $flag=1; break; } } if($flag==1) { print "Not a prime number"; } else { print "Prime number" }

 OUTPUT:  
 Enter a number : 7  
 Prime number  
 Enter a number : 16  
 Not a prime number  

No comments:

Post a Comment