Sunday, March 8, 2015

Simple Interest Calculation

Algorithm
Step 1 : Start
Step 2 : Read the values principal, rate and years
Step 3 : Compute simpleinterest using the formulae: (principal × rate × years) / 100
Step 4 : Print simpleinterest
Step 5 : Stop

Program (simpint.sh)
# Interest computation using bc
echo -n "Enter Principal amount : "
read p
echo -n "Enter number of years : "
read n
echo -n "Enter rate of interest : "
read r
si=`expr "scale=2; $p * $n *$r / 100" | bc`
echo "Simple Interest : $si"


Output
[vijai@localhost simple]$ sh simpint.sh
Enter Principal amount : 1285
Enter number of years : 3
Enter rate of interest : 5
Simple Interest : 192.75

No comments:

Post a Comment