Computer Science, asked by Enegizer, 7 months ago

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 imtiyazallam
2

Answer:

tax = (sal<=150000)? 0 : (sal<=500000)? 0.1 * sal : 0.2 * sal

Answered by anindyaadhikari13
2

\star\:\:\:\sf\large\underline\blue{Question:-}

  • Rewrite the following using ternary operator.

\star\:\:\:\sf\large\underline\blue{Answer:-}

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