Algorithm
Step 1 : Start
Step 2 : Read the value of n
Step 3 : Initialize 1 to i
Step 4 : Print n, i, n×i
Step 5 : Increment i by 1
Step 6 : Repeat steps 4 and 5 until i 10
Step 7 : Stop
Program (multable.sh)
# Multiplication table using for loop
clear
echo -n "Which multiplication table? : "
read n
for x in 1 2 3 4 5 6 7 8 9 10
do
p=`expr $x \* $n`
echo -n "$n X $x = $p"
sleep 1
done
Output
[vijai@localhost loops]$ sh multable.sh
Which multiplication table? : 6
6 X 1 = 6
6 X 2 = 12
6 X 3 = 18
6 X 4 = 24
6 X 5 = 30
6 X 6 = 36
6 X 7 = 42
6 X 8 = 48
6 X 9 = 54
6 X 10= 60
Step 1 : Start
Step 2 : Read the value of n
Step 3 : Initialize 1 to i
Step 4 : Print n, i, n×i
Step 5 : Increment i by 1
Step 6 : Repeat steps 4 and 5 until i 10
Step 7 : Stop
Program (multable.sh)
# Multiplication table using for loop
clear
echo -n "Which multiplication table? : "
read n
for x in 1 2 3 4 5 6 7 8 9 10
do
p=`expr $x \* $n`
echo -n "$n X $x = $p"
sleep 1
done
Output
[vijai@localhost loops]$ sh multable.sh
Which multiplication table? : 6
6 X 1 = 6
6 X 2 = 12
6 X 3 = 18
6 X 4 = 24
6 X 5 = 30
6 X 6 = 36
6 X 7 = 42
6 X 8 = 48
6 X 9 = 54
6 X 10= 60
No comments:
Post a Comment