Basic operators question - simple

I'm not sure but I think some of these are wrong but need someone to check thanks.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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 
Last edited on
Why don't you just test it?

Anyway: errors in first two lines:

1) 3 % 5 is 3, not 0. 5 % 3 is 2, not 1;
2) float(5/3) = float(1) = 1.0.
float(5)/3 = 5.0/3 = 1.666666...
Topic archived. No new replies allowed.