in Programming in C recategorized by
507 views
1 vote
1 vote
Let "if x then y else z" denote the expression and this expression can be represented ad "?xyz" using ternary prefix operator

the prefix operator for the following expression is

 

If a then if c-d then a+c else a*c else a+b

 

A) ?-acd+ac?+ab+ac

B) ?a?-cd+ac*ac+ab

C)?a-cd?+ac*ac+ab

D )none
in Programming in C recategorized by
507 views

2 Comments

i am getting B, is it right?
0
0
yes you are correct.

Can you please post the solution?
0
0

1 Answer

2 votes
2 votes

given that If a then if c-d then a+c else a*c else a+b

parenthesize it ===> If a then if c-d then a+c else a*c else a+b

therefore first solve if c-d then a+c else a*c

given that if x then y else z represented as ?xyz ===> we know that x?yz is ternary operator in INFIX form ==> ?xyz is ternary operator in PREFIX form ==> therefore you have to use here Prefix forms only.

let c-d = x , a+c = y and a*c = z ===> ?(c-d)(a+c)(a*c) but we need to convert x,y and z also in prefix format..

if c-d then a+c else a*c ===> ?(-cd)(+ac)(*ac) ===> ? - c d + a c * a c

 

 If a then if c-d then a+c else a*c else a+b, for solving this, let x = a, y = if c-d then a+c else a*c  and z = a+b ( prefix form of z = + a b )

therefore If a then if c-d then a+c else a*c else a+b  ===> ? a  ? - c d + a c * a c + a b

2 Comments

Thanks a lot .
0
0
@shaik nice..:)
0
0