Computer Science, asked by tejask10h352020, 2 months ago

Rewrite the following statement using ternary operator. [2]

if (basic>=5000)
netsal=basic-(8/100)*basic;
else
netsal=basic-(3/100)*basic;

Answers

Answered by Oreki
5

\text{\bf\large Given Snippet}

    \texttt{if (basic >= 5000)}\\\texttt{\: \: \:netsal = basic - (8 / 100) * basic;}\\\texttt{else}\\\texttt{\: \: \:netsal = basic - (3 / 100) * basic;}

\text{\bf\large Using Ternary Operator}

    \texttt{netsal = (basic >= 5000) ? basic - (8 / 100) * basic :}\\\texttt{\: \: \hspace{5em}  basic - (3 / 100) * basic;}\\\textsf{\: \: \: or, }\\\texttt{netsal = basic - ((basic >= 5000 ? 8 : 3) / 100) * basic;}\\

Similar questions