Q BgQuestion:

Scholar
Karma Points: 221
Respect (59%):
posted by  tokio on 8/25/2008 4:56:29 PM  |  status: Closed  

Discrete mathematics logic question

Course Textbook Chapter Problem
N/A N/A N/A N/A
Question Details:
What is the value of x after each of these statements is encountered in a computer program, if x=1 before the statement is reaches?

a)      If 1+2=3 then x:=x+1

b)      B) if (1+1=3) OR (2+2=3) then x:=x+1

c)        If (2+3=5) AND (3+4=7) then x:=x+1

d)       If (1+1=2) XOR (1+1=3) then x:x=x+1

e)       If x < 2 then x:=x+1

Bonus Point Alert! Earn +4 additional karma points for helping this annual member.

AAnswers:

Answer Question
(Cramster SME)
posted by Galois on 8/26/2008 12:17:48 AM  |  status: Live
Asker's Rating: Helpful   
Response Details:
After the execution of the given statements, we get
(a) x =2.
(b)x = 1.
(c)x = 2.
(d)x = 1.
(e)x = 2.
Scholar
Karma Points: 221
posted by tokio on 8/28/2008 1:24:37 PM  |  status: Live
Asker's Rating: N/A-Posted by Person Asking Question   
Response Details:
can you explain how you got your answers :D?
Mentor
Karma Points: 492
posted by paperwings on 8/28/2008 3:03:25 PM  |  status: Live
Asker's Rating: Helpful   
tokio's comment:
"Helped out a lot"
Response Details:
x:=x+1 simply means x++ or "add 1 more to x".

So for part (a) ,
If 1+2=3 then x:=x+1

Since 1+2 = 3, then x = x + 1 . Since you input x = 1, then x = 1 + 1 = 2.
(b) -> (e) are the same except they are conditional statements.

I'll use (e) for an example. You input x = 1
The computer reads "
If x < 2 then x:=x+1". Since 1 < 2, then you increment x by 1. So x = 1 + 1 =2.

Answer Question
Ask New Question

Join Cramster's Community

Cramster.com brings together students, educators and subject enthusiasts in an online study community. With around-the-clock expert help and a community of over 100,000 knowledgeable members, you can find the help you need, whenever you need it. Join for free today » How Cramster is different than tutoring »