Get Update on recent Technology & Programming

Sunday, 29 October 2017

Shell Script Program To Print Prime Numbers upto a Given Number

Posted by   on Pinterest

Shell Script Program To Print Prime Numbers upto a Given Number




 echo Enter a number till which you want to print the prime numbers  
 read num  
 c=2  
 while [ $c -le $num ]  
 do  
 flag=1  
 i=2  
 while [ $i -lt $c ]  
 do  
  a=`expr $c % $i`  
  if [ $a -eq 0 ]  
  then  
  flag=0  
  fi  
  i=`expr $i + 1`  
 done  
 if [ $flag -ne 0 ]  
 then  
  echo $c  
 fi  
 c=`expr $c + 1`  
 done  

No comments:
Write comments

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