Get Update on recent Technology & Programming

Sunday, 29 October 2017

Shell Script Program To Check Number is Prime Or Not

Posted by   on Pinterest

Shell Script Program To Check Number is Prime Or Not



 echo Enter a number  
 read num  
 i=2  
 flag=1  
 while [ $i -lt $num ]  
 do  
  a=`expr $num % $i`  
  if [ $a -eq 0 ]  
  then  
  flag=0  
  fi  
  i=`expr $i + 1`  
 done  
 if [ $flag -eq 0 ]  
 then  
  echo $num is not a Prime number  
 else  
  echo $num is a Prime number  
 fi  

2 comments:
Write comments
  1. there is an error in this logic.. loop must be stooped with break when flag is found 0 or otherwise it will keep number checking for next iteration and result will be irrelevant...

    ReplyDelete
  2. In any case, numerous sort of site write, for example, arranged advertisements, discussion, informal community, social bookmark and the other content that isn't accessible in the free web content.
    script coverage

    ReplyDelete

Hey, we've just launched a new custom color Blogger template. You'll like it -
Join Our Newsletter