Things to note: 1. In the computation part, the real value are used (note 4.0 and 3.0).
If integer value is used (4/3), then the output will be wrong. Since 4/3 produces result as 1.
Because if both operands are int then result will be of type "int".
2. Both / and * operator same precedence so they are evaluated from left to right.
stepwise evaluation of the expression is shown below.
c = 4.0/3.0*3.14*5.0*5.0
| Expression | operation | |
|---|
| c = 1.3333*3.14*5.0*5.0 | / |
| c = 4.186562*5.0*5.0 | * |
| c = 20.93281*5.0 | * |
| c = 104.66 | * |
Powered by Open Source Programmers
|