SHELL PROGRAM
Program to find mean and standard deviation of three numbers | Shell program|
#!/bin/bash
echo "Enter first number:"
read n1
echo "Enter second number:"
read n2
echo "Enter third number:"
read n3
m=$(($n1 + $n2 + $n3))
mean=$(echo "scale=2;$m / 3"|bc)
echo
echo "mean=$mean"
y1=$(echo "$n1-$mean"|bc)
y2=$(echo "$n2-$mean"|bc)
y3=$(echo "$n3-$mean"|bc)
x1=$(echo "$y1 ^ 2"|bc)
x2=$(echo "$y2 ^ 2"|bc)
x3=$(echo "$y3 ^ 2"|bc)
s=$(echo "scale=2;$(echo $x1 + $x2 +$x3|bc)/2"|bc)
sd=$(echo "sqrt($s)"|bc)
echo "standard deviation=$sd"
OUTPUT
Enter first number:
5
Enter second number:
10
Enter third number:
15
Mean=10.00
Standard deviation=5.00
echo "Enter first number:"
read n1
echo "Enter second number:"
read n2
echo "Enter third number:"
read n3
m=$(($n1 + $n2 + $n3))
mean=$(echo "scale=2;$m / 3"|bc)
echo
echo "mean=$mean"
y1=$(echo "$n1-$mean"|bc)
y2=$(echo "$n2-$mean"|bc)
y3=$(echo "$n3-$mean"|bc)
x1=$(echo "$y1 ^ 2"|bc)
x2=$(echo "$y2 ^ 2"|bc)
x3=$(echo "$y3 ^ 2"|bc)
s=$(echo "scale=2;$(echo $x1 + $x2 +$x3|bc)/2"|bc)
sd=$(echo "sqrt($s)"|bc)
echo "standard deviation=$sd"
OUTPUT
Enter first number:
5
Enter second number:
10
Enter third number:
15
Mean=10.00
Standard deviation=5.00
Post a Comment
0 Comments