Shell Script to find sum, product and average of given numbers - The Coding Shala

Home >> Scripting >> Sum, product and average

Shell Script to find the sum, product, and the average of given numbers

Read four integer numbers from the user and find the sum, product, and average of these four numbers?

Code: 

#!/bin/bash
echo "enter four integers"
read a b c d
sum=$(echo "$a + $b + $c + $d" | bc -l)
average=$(echo "$sum / 4" | bc -l)
product=$(echo "$a * $b * $c * $d" | bc -l)
echo "sum =  $sum"
echo "Average =  $average"
echo "Product = $product"



Other Posts You May Like
Please leave a comment below if you like this post or found some error, it will help me to improve my content.

Comments

Popular Posts from this Blog

Binary Number with Alternating Bits LeetCode Solution - The Coding Shala

Time Complexity, Space Complexity, Asymptotic Notations - The Coding Shala

Java Program to Reverse a String using Stack - The Coding Shala

Java Program to Find GCD or HCF of Two Numbers - The Coding Shala

Find Second Smallest Element in the Array - The Coding Shala