Professional Documents
Culture Documents
Os Experiment 11
Os Experiment 11
Os Experiment 11
#!/bin/bash
n=$1
# make sure command line arguments are passed to the script
if [ $# -eq 0 ]
then
echo "A shell script to print multiplication table."
echo "Usage : $0 number"
exit 1
fi
chmod +x multiplication.sh
./multiplication.sh
./multiplication.sh 13
Sample outputs:
13 * 1 = 13
13 * 2 = 26
13 * 3 = 39
13 * 4 = 52
13 * 5 = 65
13 * 6 = 78
13 * 7 = 91
13 * 8 = 104
13 * 9 = 117
13 * 10 = 130
72.2
1
#!/bin/bash
n=6
a=$n/2
for((i=$a-1;i>=0;i–))
do
for((k=i; k<=$n; k++))
do
echo -ne ” “;
done
for((j=1;j<=2*i-1;j++))
do
echo -ne “*”;
done
echo;
done
73.2
BASIS FOR
RECURSION ITERATION
COMPARISON
Basic The statement in a body of function calls the Allows the set of instructions to be repeatedly
function itself. executed.
Termination A conditional statement is included in the body The iteration statement is repeatedly executed
of the function to force the function to return until a certain condition is reached.
without recursion call being executed.
Condition If the function does not converge to some If the control condition in the iteration statement
condition called (base case), it leads to infinite never become false, it leads to infinite iteration.
recursion.
Infinite Infinite recursion can crash the system. Infinite loop uses CPU cycles repeatedly.
Repetition
Stack The stack is used to store the set of new local Does not uses stack.
variables and parameters each time the
function is called.
Overhead Recursion possesses the overhead of repeated No overhead of repeated function call.
2
BASIS FOR
RECURSION ITERATION
COMPARISON
function calls.
Size of Code Recursion reduces the size of the code. Iteration makes the code longer.
73.3
N=6
a=0
b=1
Input : 5
Output :
Fibonacci Series is :
0
1
1
2
3
73.4
OUTPUT:
73.5
Num=123
g=$Num
# calculate sum of
# digit
s=$(( $s + $k ))
done
echo "sum of digits of $g is : $s"
Output
sum of digits of 123 is : 6
74.1
4
for day in Sunday Saturday Monday Tuesday Wednesday Thursday Friday
do
echo "Welcome $day day"
done
output
Welcome Sunday day
Welcome Saturday day
Welcome Monday day
Welcome Tuesday day
Welcome Wednesday day
Welcome Thursday day
Welcome Friday day