0

How to use condition operator in c lang

i used its as (c=='+')?printf("%d",a+b): continue; (c=='-')?printf("%d",a-b): continue; (c=='*')?printf("%d",a*b): continue; so is this wrong........ plz rply its urgent

16th May 2018, 8:08 AM
mukul verma
mukul verma - avatar
3 Réponses
+ 3
Agreeing with Programanta ludanto, you should probably use a switch statement instead of the ternary condition operator.
16th May 2018, 10:49 AM
Maxwell Anderson
Maxwell Anderson - avatar
+ 2
(condition) ? a : b The a and b must be the same types. So you should use if or switch statement like below. switch(c) { case '+': print(.....); break; case '-': ..... case '*': ..... default: continue; }
16th May 2018, 8:23 AM
Disvolviĝo;
Disvolviĝo; - avatar
0
buddy i know that but still i want to use condition operator so plz suggest me a way
16th May 2018, 8:28 AM
mukul verma
mukul verma - avatar