retagged by
1,196 views
0 votes
0 votes
Assume ×, –, + and / are operators. Precedences and associativity given for those operators as following:

1. × has highest precedence among all operators and it is left associative

2. –, + and / are having equal precedence and they are right associative.

Using × as Multiplication, – as Subtraction, + as Addition and / is Division.

The output of the following expression : 10 × 10 – 5 + 15 – 5 × 10 / 5 is ________.
retagged by

2 Answers

Best answer
5 votes
5 votes

10 × 10 – 5 + 15 – 5 × 10 / 5

1) x having higher precedence so we will solve for a x b   where a , b are numbers  

10x10=100 (replace 10x10 by 100) 

5x10=50 ( replace 5x 10  by 50)

100 - 5 + 15 -50 / 5

2) now we are left with + , - , x , /

    but they have same precedence , so we will  sove them according to their associativity 

     therefore  start solving from right  to left    since  associativity is right  ( similarly if associtivity been left  then  we would start        from left to right

now  100 - 5 + 15 - (50 / 5)-----> 10(replace)

         = 100 - 5 + (15 - 10)------->5(replace)

         = 100 - (5 +  5)------->10(replace)

          = (100 - 10)------->(replace)

           = 90 ----->answer

 

selected by
2 votes
2 votes
10*10-5+15-5*10/5

100-5+15-50/5

100-5+15-10

100-5+5

100-10

90

Related questions

1 votes
1 votes
2 answers
1
0 votes
0 votes
1 answer
2
2 votes
2 votes
2 answers
3