Can someone check if I am doing these right please, thanks ?

int a=3, b=5, x;
x= a/b + b/a +a%b + b%a; cout << x;    //  x=0+1+0+1= 2
y=float(b/a)+ float(b)/a; cout << y;   //  y=1.6+1=2.6
z=a*b/2; cout << z;                    //  z= 4
w=pow(b, a)+sqrt(a+b);  cout << w;     //  w=125+2sqrt(2)

int a=4, b=7, x; 
a++; --b;
x=a+b; cout<<"x"<< x;        //x=11

a=4; b=8
x=a++*--b; cout<<"x="<< x;   //x=35

a=3; b=5;
a+=3+b; b*=2;
x=a+b; cout<< "x="<< x;      //x=13

Edited by DS9596: added more

3 Years
Discussion Span
Last Post by YarMak

If the comments you added are supposed to be the answers you want, then no they are not all right. Line 11 gives the right answer the rest give different answers


Line 3, 4 and 5 needs declaration y, z and w. otherwise, with declaration, line 3 will give 1 since the operands are 'int'. line 4 will not give 4. it will give 6 or 7 depending on the precidence. line 5 will give 127 or 127.2828 depending on the declaration of w.
Line 18 has an out put of 28 becouse, a was increased after the operation while b is decreased before.
In line 18, the out come is 21 since a=a+3+b and b=b*2.

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.