We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- Linux Shell
- Bash
- The World of Numbers
- Discussions
The World of Numbers
The World of Numbers
+ 0 comments #!/bin/bash # Read the input integers read a read b # Calculate sum, difference, product, and quotient sum=$((a + b)) difference=$((a - b)) product=$((a * b)) quotient=$((a / b)) # Print the results echo "$sum" echo "$difference" echo "$product" echo "$quotient"
+ 2 comments I think is better solution
#!/bin/bash read num1 read num2 for x in {+,-,'*','/'} do echo "$(($num1$x$num2))" done
+ 0 comments read x read y
echo "x+((y))" echo "x*((y))"
+ 0 comments read num1 read num2 echo "$(($num1+$num2))" echo "$(($num1-$num2))" echo "$(($num1*$num2))" echo "$(($num1/$num2))"
+ 0 comments Using simple for loop
read num1 read num2 for x in {$num} do echo "$(($num1+$num2))" echo "$(($num1-$num2))" echo "$(($num1*$num2))" echo "$(($num1/$num2))" done
Load more conversations
Sort 168 Discussions, By:
Please Login in order to post a comment