Ask Question
26 February, 11:25

Assume that an int variable is Quadrilateral has been declared, and that another int variable, number Of Sides has been declared and initialized. Write a statement that assigns the value 1 if number Of Sides is exactly 4 and 0 otherwise.

+3
Answers (1)
  1. 26 February, 13:54
    0
    The answer to this question can be given as:

    Statement:

    isQuadrilateral = (numberOfSides = = 4) ? 1 : 0;

    //check condition using ternary operator.

    Explanation:

    we know that both (Quadrilateral, numberOfSides) is already declared in the program. So the statement for check condition is (isQuadrilateral = (numberOfSides = = 4) ? 1 : 0; ). To check this condition we use the ternary operator. In this operator, we also check another condition. The syntax of ternary operator (condition? value_if_true : value_if_false). In this statement on the lift side we use the variable for check condition and right side we check condition if the value is true it prints 1 else it will print 0.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Assume that an int variable is Quadrilateral has been declared, and that another int variable, number Of Sides has been declared and ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers