-1

How can I multiply by decimal numbers and get the result in decimal?? How can the code be modified to meet these two conditions? enter image description here

1 Answers1

0

You could call the desk-calculator program to do the arithmetic:

v1 = 3
pi = 3.14
$ echo "Area of Circle =" $(dc --expression="$pi $v1 * $v1 * p")
Area of Circle = 28.26

In case you aren't familiar with it, dc uses reverse-polish syntax:

  • stack $pi
  • stack $v1
  • replace the top two numbers with their product
  • stack $v1
  • replace the top two numbers with their product
  • print the top of the stack

These are equivalent expressions:

$ echo "Area of Circle =" $(dc --expression="$pi $v1 * $v1 * p")
Area of Circle = 28.26

$ echo "Area of Circle =" $(dc --expression="$pi $v1 2 ^ * p") Area of Circle = 28.26

$ echo "Area of Circle =" $(dc --expression="$v1 2 ^ $pi * p") Area of Circle = 28.26

  • when use this command>>> linux write: dc stack empty & pi: not found command – Amany ahmad Nov 02 '22 at 06:04
  • @Amanyahmad, did you first set the values of pi and v1? Before doing the echo … line, try echo $pi and echo $v1 to verify that they are set correctly. ¶ Also, make sure you are using the bash shell: echo $SHELL should print "/bin/bash". – Ray Butterworth Nov 02 '22 at 13:09