Condition operator question. (a) What is conditional operator(?:)in C? How is it
ID: 3766431 • Letter: C
Question
Condition operator question. (a) What is conditional operator(?:)in C? How is it use? (b) Assume that variables final, initial and intermediate have all been declared as integer data type and assigned valid integer values. Rewrite the following statement using an if else structure.
Final=initial*(initial>10?intermediate+10:intermediate-10);
(c) rewrite the code fragment below using conditional operator(?:) if (input >1&&input <4) output =output-5 ; else output = output +5;
//can someone explain to me how to do this question I am very lost
Explanation / Answer
a) The conditional operator (?) evaluates an expression returning a value if that expression is true and a different one if the expression is evaluated as false.
Its format is: condition ? result1 : result2
If condition is true the expression will return result1, if it is not it will return result2.
b) If(initial>10)
{
Final=initial*(intermediate+10);
}
else{
Final=initial*(intermediate-10);
}
c) ((input >1&&input <4) ? output-5 : output +5);
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.