what z=

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lizaww
    New Member
    • Nov 2008
    • 6

    what z=

    With x = 5 and y = 8 and z = 5, what is the value of the variable z after the execution of the following pseudo-code:
    If ((5 <= 20) && (8 >= 10)) Then
    z = 5 + 1
    Else
    z = 5 – 1
    End If
    is z= to 4?
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    The variables x and y don't participate in any part of that program snippet so I
    don't know why you mentioned them. What happened when you wrote a little
    C or C++ program and executed it? This is not an answer-my-silly-riddles forum.

    kind regards,

    Jos

    Comment

    • Ganon11
      Recognized Expert Specialist
      • Oct 2006
      • 3651

      #3
      This code depends on the two logical expressions "5 <= 20" and "8 <= 10". Are you telling me you don't have enough math basis to determine the truth value of these expressions?

      You're smarter than that, I guarantee it.

      Comment

      • donbock
        Recognized Expert Top Contributor
        • Mar 2008
        • 2427

        #4
        Originally posted by lizaww
        With x = 5 and y = 8 and z = 5, what is the value of the variable z after the execution of the following pseudo-code:
        If ((5 <= 20) && (8 >= 10)) Then
        z = 5 + 1
        Else
        z = 5 – 1
        End If
        is z= to 4?
        Umm. Your pseudo-code doesn't make much sense to me, perhaps you meant ...
        Code:
        if ((x <= 20) && (y >= 10)) Then
            z = x + 1
        Else
            z = x - 1
        End If
        In any case, the key is determining which leg of the If statement executes. The question to answer is whether the If expression is true or false. What do you think? Why do you think so?

        Comment

        Working...