Hi
Hi
Campus
int n = 4 – 3 + 23 % 8 / 4 * 4; n=5
Page 1 of 21
(8 - 3 / 4 >= 11 * (5 – 2) % 3) True
int x = 2 % 2 + 2 * 2 – 2 / 2 3
Page 2 of 21
float x= float(17 / 4) + int(2.5 – 2) 4
int d = (5 + 3) * 2 – 7 / 3; 14
Page 3 of 21
int f = 2 * (4 / 2) + 3 % 2; 5
boolean h = !(true && false) || (true && false) && true; True
int i = 10 / 2 + 3 * (8 % 3) – 1; 12
Page 4 of 21
Sample Output
int x = 7, y = 14, z = 3; True
x >= 5 && y != 12
int m = 4, n = 8, o = 2; False
!(m + n > o * 3) && n % o == 0
int d = 6, e = 3, f = 9; False
d * e - f != 12 || d / e == f % 2
int g = 2, h = 7, i = 5; True
g + h > i && !(g == h) || g * h == i
Page 5 of 21
int a = 8, b = 12, c = 4; True
!(a < b) && c != 2 || a - b > 0
int u = 5, v = 3, w = 1; True
(u + v) * w == u * w + v * w && !(u - v > w)
int s = 7, t = 4, x = 2; True
s > t && t < x || s == t * x
int aa = 6, bb = 3, cc = 2; False
!(aa % bb == cc && bb > cc) && aa / bb == cc
Page 6 of 21
Find errors in the following statements and correct them.
char no[] = Hello World; String values are written in double quotes
define char ch 'B' The sign # is used with define. It does not use data types.
z=4.0 w*y;
y = yz
a = 6b3;
c = 3(a + b);
z = 7w + xy;
(x + y)z;
(x + 3y) + (2x – y)
Page 7 of 21
For the given code write down the output for given values.
Sample Code Output
int m=5,n=10,q=20;
if(q/n*m) William Gates Carlos Slim Helu
cout<<"William Gates";
else
cout<<" Warren Buffet";
cout<<" Carlos Slim Helu";
int x;
if(x == 3) When x = -5
{
cout<<"x = "<< x<<endl; x = -5
cout<<"The if condition is fulfilled!\n"; The if condition is not fulfilled!
}
else
{ When x = 3
cout<<"x = "<< x<<endl;
cout<<"The if condition is not fulfilled!\n"; x=3
} The if condition is fulfilled
int main() When x = 3
{
int x;
if (x < 1) When x = -2
cout<<"hello"; Hello no
if (x == 5)
cout<<"hi"; When x = 5
else hi
cout<<"no";
}
int numb1, numb2; numb1=5 , numb2=3
if(numb1==numb2) 5>3
cout<<"Result: “<<numb1<<”=”<<numb2;
else numb1=2 , numb2=3
if(numb1>numb2) 3>2
cout<<"Result: "<<numb1<<”>”<<numb2; numb1 = 5, numb2=5
else 5=5
cout<<"Result: "<<numb2<<”>”<<numb1;
int k; When k = 20
if(k < 90) Grade F
if(k < 80)
if(k < 70) When k = 75
if(k < 60) Grade C
cout<<"Grade F.\n";
else When k = 62
cout<<"Grade D.\n"; Grade D
else
cout<<"Grade C.\n"; When k = 95
else Grade A
cout<<"Grade B.\n";
else When k = 85
cout<<"Grade A.\n"; Grade B
Page 8 of 21
When K = 63
int k;
Grade D
if(k > 69)
{ When K = 90
if(k > 89)
cout<<"Grade A.\n"; Grade A
else
{ When K = 75
if(k > 79)
cout<<"Grade B.\n"; Grade C
else
cout<<"Grade C.\n"; When K = 59
}
} Grade F
else When K = 83
{
if(k > 59) Grade B
cout<<"Grade D.\n";
else
cout<<"Grade F.\n";
}
When K = 45
int k, a=0, b=0, c=0, d=0, f=0; A's = 0 B's = 0 C's = 0 D's = 0 F's = 1
cout<<"A\'s = "<< a;
cout<<"B\'s = " <<b;
cout<<"C\'s = " <<c;
cout<<"D\'s = " <<d;
cout<<"F\'s = “<< f;
Page 9 of 21
degreesOutside= 80, numberOfClouds=10
int degreesOutside;
int numberOfClouds; no output
if (degreesOutside > 70 && numberOfClouds < 5) degreesOutside= 80, numberOfClouds= -1
{
cout<<"Wear sun screen!"; Wear sun screen!
}
Output
When myAge = 95
int myAge;
You are not quite in your
if ((myAge >= 0 && myAge < 3) || myAge > 90 && myAge<=100) peak.
cout<<"You are not quite in your peak."; When myAge = 0
No output
Page 10 of 21
Page 11 of 21
int a = 5; b =
int b = ++a + 2;
int x = 3;
int y = x++ * 2 + --x;
y=
Page 12 of 21
int m = 7;
int n = m-- + ++m * 2 – 3;
n=
int p = 4;
int q = ++p * 2 – p-- + p++;
q = 10
int r = 6;
int s = r++ + --r * 3 / 2;
s = 14
int u = 8;
int v = u-- + ++u – u++ + --u;
v = 18
int w = 10;
int x = w-- + w++ + --w + w--;
x = 27
int a = 3;
int b = a++ + a-- – ++a + --a;
b=4
Page 13 of 21
int c = 5;
int d = ++c * 2 – c++ + --c * 3;
d = 19
int e = 6;
int f = e++ + ++e * e-- / --e;
f = 22
int a = 5;
int b = a++ * --a + a-- – ++a;
b = 24
int x = 4;
int y = ++x * 2 + x-- * 3 – --x;
y = 17
int e = 9;
int f = e++ + --e * 2 + ++e – e-- * 3;
f = 13
Page 14 of 21
int a = 3;
int b = a-- + ++a * 2 – a++ + --a;
b=8
int a = 3, b = 5, c = 7;
int result = ++a * (b-- + c++) – (--b + ++c);
result = 26
int x = 2, y = 4, z = 6;
int outcome = x++ + (--y * z--) – (++x * y);
outcome = -15
int m = 4, n = 6, o = 8;
int answer = ++m * (n++ + --o) – (m-- + ++n);
answer = 22
int p = 7, q = 5, r = 3;
int result = p-- * (q++ – ++r) + (--q + r--);
result = 24
Page 15 of 21
int s = 2, t = 3, u = 4;
int value = s++ * (t-- + --u) + (++t * u--);
value = 18
int v = 6, w = 3, x = 2;
int result = v++ * (++w + x--) – (--v * w);
result = 24
int a = 5, b = 2, c = 8;
int output = ++a * (b-- + --c) + (a-- + ++b * c--);
output = 68
int d = 4, e = 3, f = 7;
int value = --d * (e++ + f--) – (++e * --f);
value = 14
int j = 8, k = 6, l = 3;
int outcome = j++ * (--k + l++) – (j-- + ++k * --l);
outcome = 29
Page 16 of 21
for (int i = 1; i <= 10; i += 2)
{
cout << i << " ";
}
int n;
cout << "Enter a number: ";
cin >> n;
for (int i = 1; i <= n; i++) {
cout << i << " ";
}
int i, p=1;
for(i=1; i<6; i+=1)
{
P*=2;
}
Cout<<”\npis=”<<p;
Page 17 of 21
for (float i = 0; i < 1; i += 0.1) {
cout << i << " ";
}
int x=1;
while(x != 12)
{
Cout<<x<<”\n”;
X+=2;
}
int x=1;
while (x<9)
{
X++;
If(x%2 == 1)
cout<<x<<”+”;
}
Page 18 of 21
for (int i = 0; i < 5; i++)
{
cout << i << " ";
}
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 2; j++) {
cout << "i: " << i << ", j: " << j <<
endl;
}
for (int i = 1; i <= 10; i++)
{
if (i % 2 == 0) {
cout << i << " ";
}
}
int count = 1;
For( ; ; count<5)
if(count<5)
Page 19 of 21
cout<<count;
else
break;
Page 20 of 21
sum = 0;
outerCount = 1;
while (outerCount <= 5)
{
innerCount = 1;
while (innerCount < =outerCount)
{
sum = sum + innerCount;
innerCount++ ;
}
outerCount++;
}
int i, j, limit = 6;
for ( i = limit; i > 0; i-- )
{
for (j = 1; j<=i ; j++)
{
if (i == 1 || i = = limit || j = =1 || j = = i)
cout<<i;
else
cout<< “ “;
}
cout << endl;
}
b. Using the above code, what will the value of x be after execution?
c. Using the above code, what will the value of a be after execution?
Page 21 of 21