Ask Question
9 October, 19:36

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.

+4
Answers (1)
  1. 9 October, 19:42
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers