Os MidTerm Solution
Os MidTerm Solution
Os MidTerm Solution
1
S peedup = B + 1n (1−B)
n= 15
Speedup = 10
1
10 = 1
B + 15 (1−B)
10 10
10B + 15 − 15 B =1
140B = 5
1
B = 28 = 0.0357
2)
function print_primes(){
for((i=2;i<=1000;i++)){
x=0;
for((j=2;j*j<=i;j++)){
if((i%j==0))
then
x=1
break
fi
}
if((x==0))
then
echo $i
fi
}
}
function array_average(){
read -p "enter array : " -a r;
cho "Array is : ${r[@]};"
e
tot=0
for i in ${r[@]}
do
et tot+=$i
l
one
d
count=${#r[@]}
echo "the average is : $(($tot/$count))" # this will print the average
as integer
#printf %.10f "$((1000000000 * tot/count))e-9" # this will print the
average as float
}
function print_even(){
read -p "enter 6 numbers in one line : " -a r;
for i in ${r[@]:0:6} # take only the first 6 numbers in case he nade
nustaje and entered more than 6 variables
do
if((i%2==0))
then
echo "$i";
fi
done
}
function create_dirs(){
function check_exist(){
read -p "enter file name : " f
if [ -f $f ]
then
echo "the file exists"
else
echo "the file dosen't exists"
fi
}
read -p "enter letter " X;
p)
print_primes
;;
a)
array_average
;;
o)
print_even
;;
f)
create_dirs
;;
e)
check_exist
;;
*)
cho "letter is not valid";
e
;;
esac