Loading…
OS · Loops & numbers · Program 07 · In the record
write a shell script to input a number and check whether it is a prime number or not
1#!/bin/bash2 3echo "Enter a number:"4read n5 6if (( n < 2 ))7then8 echo "$n is not a Prime number"9 exit 010fi11 12i=213prime=114 15while (( i * i <= n ))16do17 if (( n % i == 0 ))18 then19 prime=020 break21 fi22 i=$((i + 1))23done24 25if (( prime == 1 ))26then27 echo "$n is a Prime number"28else29 echo "$n is not a Prime number"30fi29Enter a number: 29 29 is a Prime number
Run program 07 in your browser
bash · just-bash. Change the code or the input, run it, break it, and see what happens.