Thursday, May 1, 2008

Write a program to print all prime numbers from 1 to 300. (Hint: Use nested loops, break and continue)

# SS25

# Shell script to print prime numbers from 1 to 300

# Usage: SS25

n=1

echo $n

while [$n -le 300]

do

i=2

while [$i -le ‘expr $n -1‘]

do

if[‘expr $n % $i‘ -eq 0]

then

break

else

i=’expr $i+1‘

fi

done

if[$n -eq $i]

then

echo $n

fi

n=‘expr $n+1‘

done

No comments: