0% found this document useful (0 votes)
11 views4 pages

Shell Program for Odd/Even Sum

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)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views4 pages

Shell Program for Odd/Even Sum

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)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

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

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

Program to generate prime numbers between 1 and 50.


[1ecea28@CMC CSE]$ vi [Link]

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 [Link]

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

Program to find out sum of n numbers :


[1ecea28@CMC CSE]$ vi [Link]

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 [Link]

enter no 13 prime number

Sum of even and odd numbers :


[1ecea28@CMC CSE]$ vi odd/[Link]

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/[Link]

number of entries 5 the sum of numbers is 15

You might also like