Saturday, March 27, 2021

Print Multiplication table of any number | Unix programming | Unix Shell scripting | 27/03/2021

Print Multiplication table of any number | Unix programming | Unix Shell scripting | 27/03/2021




Algorithm :

  1. Take input from the user.
  2. assign it to a variable 'n'
  3. Declare a variable 'i'
  4. Now, apply while loop with condition ( 'i' less than equal to 10 )
  5. Start the loop by ( do )
  6. Store the result of multiplication of  'n' and 'i' in another variable 'res'
  7. Print the result
  8. Increment the variable 'i'
  9. 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 : 



So, this was unix shell script for displaying the table of any number.
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

Print Multiplication table of any number | Unix programming | Unix Shell scripting | 27/03/2021

Print Multiplication table of any number | Unix programming | Unix Shell scripting | 27/03/2021 Algorithm : Take input from the user. assign...