Arithmetic Operations HackerRank Solution

Hello coders, In this post, you will learn how to solve the Arithmetic Operations HackerRank Solution. This problem is a part of the Linux Shell series.

Arithmetic Operations HackerRank Solution
Arithmetic Operations HackerRank Solution

Problem

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+503/20 + (192)/7

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

Sample Input 3
(-105.57+503)/20 + (19^2)/7

Sample Output

Sample Output 1
17.929

Sample Output 2
-45.929

Sample Output 3
22.146

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 chase2learn. This tutorial is only for Learning and Educational purpose.

Sharing Is Caring