Print Multiplication table of any number | Unix programming | Unix Shell scripting | 27/03/2021
Algorithm :
- Take input from the user.
- assign it to a variable 'n'
- Declare a variable 'i'
- Now, apply while loop with condition ( 'i' less than equal to 10 )
- Start the loop by ( do )
- Store the result of multiplication of 'n' and 'i' in another variable 'res'
- Print the result
- Increment the variable 'i'
- Close the loop by ( done )
Program
echo "Enter the number : "
read n
i=1
while [ $i -le 10 ]
do
let res=n*i
echo " $n x $i = $res "
let i=i+1
done
Execution on Unix terminal :
Output :
Please feel free to ask any questions in your mind.
You may have different solution to this question, please let me know if there is any better answer, I would happy to accept that.
Thank you and Happy Learning.
Please comment if you have any doubts regarding the post.
No comments:
Post a Comment