0

a = 2;
b = 3;
a = (a + b) % 2;
b = b – a;
a = a * b;
cout << a << "\n" << b ;

What is the output for a and b?
------------------------------------------------------------
Why is a 3 and b 2 is this one

a = 2;

b = 3;

a = a + b;

b = a – b;

a = a – b;

cout <<a<<endl;

cout << b;

3
Contributors
11
Replies
12
Views
9 Years
Discussion Span
Last Post by VernonDozier
0

>What is the output for a and b?
Run it and see.

>Why is a 3 and b 2 is this one
2 + 3 = 5
5 - 3 = 2
5 - 2 = 3

0

>yea i ran it but got an error so i dont know
You probably got the same error I did. It's hard to see, but – and - are not the same character. If that doesn't fix your problem, post the errors you're getting and all of the code.

0

You have two separate pieces of code. Which one are you asking about?

This one?

a = (a + b) % 2;
b = b – a;
a = a * b;

or this one?

a = a + b;
b = a – b;
a = a – b;

And do you still have the error?

0

By that do you mean:

1) Your program doesn't run still?
2) Your program runs and gives you a different answer?
3) Your program and mine give the same results, but the answer seems wrong to you?


If it's 1 or 2, please post your full program.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.