if(sal<=150000) tax=0; else if (sal<=500000) tax=0.1*sal; else tax=0.2*sal; convert to ternary operator
Answers
Answered by
2
Answer:
tax = (sal<=150000)? 0 : (sal<=500000)? 0.1 * sal : 0.2 * sal
Answered by
2
- Rewrite the following using ternary operator.
Given code segment,
if(sal <=150000)
tax =0;
else if(sal<=500000)
tax =0.1*sal;
else
tax=0.2*sal;
The above code can be written using ternary operator as,
tax =(sal<=150000)?0:(sal<=500000)?0.1*sal:0.2*sal;
Similar questions