0% found this document useful (0 votes)
16 views

Shell Program

This document contains summaries of 4 Bash shell scripts: 1) An area.sh script that calculates the area of a circle given a radius. 2) A prime.sh script that prints all prime numbers between 1 and 50. 3) A sumofn.sh script that determines if a user-input number is prime or not. 4) An odd/even.sh script that calculates the sum of user-input numbers.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Shell Program

This document contains summaries of 4 Bash shell scripts: 1) An area.sh script that calculates the area of a circle given a radius. 2) A prime.sh script that prints all prime numbers between 1 and 50. 3) A sumofn.sh script that determines if a user-input number is prime or not. 4) An odd/even.sh script that calculates the sum of user-input numbers.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Program to find area of a circle: [1ecea28@CMC CSE]$ vi area.sh echo enter radius read r area=`expr $r \* $r \* 3.

14|bc` echo area is $area output: [1ecea28@CMC CSE]$ sh area.sh enter radius 6 area is 113.04

Program to generate prime numbers between 1 and 50.


[1ecea28@CMC CSE]$ vi prime.sh

for((i=2;i<51;i++)) do flag=0 for((j=2;j<=i;j++)) do if [ `expr $i % $j` -eq 0 ] then flag=`expr $flag + 1` fi done if [ $flag -eq 1 ] then echo $i fi done output:
[1ecea28@CMC CSE]$ sh prime.sh

2 3 5 17 19 23 29 31 37 41 43 47

Program to find out sum of n numbers :


[1ecea28@CMC CSE]$ vi sumofn.sh

echo enter number of entries echo "enter no" read n i=2 m=`expr $n / 2` until [ $i -gt $m ] do q=`expr $n % $i` if [ $q -eq 0 ] then echo "not a prime number" exit fi i=`expr $i + 1` done echo "prime number" Output:
[1ecea28@CMC CSE]$ sh sumofn.sh

enter no 13 prime number

Sum of even and odd numbers :


[1ecea28@CMC CSE]$ vi odd/even.sh

echo enter number of entries read n sum=0 declare a[100] for((i=0;i<n;i++)) do read a[$i] sum=`expr $sum + ${a[$i]}` done echo The sum of numbers is $sum

output:
[1ecea28@CMC CSE]$ sh odd/even.sh

number of entries 5 the sum of numbers is 15

You might also like