Arithmetic Operations – HackerRank Solution

In this article, we will solve Arithmetic Operations HackerRank Solution. This problem (Arithmetic Operations) is a part of Linux Shell series.

Task

A mathematical expression containing +,-,*,^, / and parenthesis will be provided. Read in the expression, then evaluate it. Display the result rounded to 3 decimal places.

Constraints

All numeric values are <= 999.

Sample Input

Sample Input 1

5+50*3/20 + (19*2)/7

Sample Input 2

-105+50*3/20 + (19^2)/7

Sample Input 3

(-105.5*7+50*3)/20 + (19^2)/7

Sample Output

Sample Output 1

17.929

Sample Output 2

-45.929

Sample Output 3

 22.146

Solution – Arithmetic Operations – HackerRank Solution

read x
printf "%.3f\n" `echo "$x" | bc -l`

Note: This problem (Arithmetic Operations) is generated by HackerRank but the solution is provided by CodingBroz. This tutorial is only for Educational and Learning purpose.

Leave a Comment

Your email address will not be published. Required fields are marked *