You are on page 1of 2

1.

Identify and correct the error(s):


a) if ( age >= 80 ) ;
cout << "Age is greater than or equal to 80"<endl;
else
cout << "Age is less than 80" << endl" ;

b) Ffor ( x = 100,; x >= 1,; x++ x- - )


cout << x << endl;

c) Wwhile ( x <= 100 )


{
total += x;
x++;
}

d) counter = 2;
do
{
cout << counter << endl;
counter += 2;
}Wwhile ( counter <100 ) ;

e) switch ( value % 2 )
{
case 0:
cout << "Even integer" << endl;
break;
case1:
cout << "Odd integer" << endl;
}

2. Given the following declarations:

int count = 0, limit = 10, x = 3, y = 5, z = 7;


bool c1 = true, c2 = false;

State whether the result of each the following expressions is true or false.

a) (count == 0) && (limit > 12) false


b) (limit > 20) || (count < 5) true
c) !(count == 12) true
d) x == 3 true
e) x < y true
f) x >= y false
g) x != y 2 false
h) x < 10 true
i) x >= 0 && x < 10 true
j) x >= 0 && x < 2 false
k) x < 0 || x < 10 true
l) x < 0 || x > 10 false
m) !c1 false
n) !c2 true
o) c1 && c2 false

3. Write the output of the following segments:

Program Output
1. Given that the value of x is 3 Enter a value
3
int x;
x is not zero
cout <<"Enter a value\n";
cin >> x;
if(x==0)
{
cout << "x is zero\n";
}
else
{
cout << "x is not zero\n";
}

2. int x=0; 0
while( x < 5) 0
cout << x << endl; //will be repeated
0 it will print zeros to infinity
x ++;
cout << x << endl; // because there is no { } so the first
cout line will be repeated (nonstop)
3. float x; x= 17
x = 3.0 * 4.0 + 3 + 4 / 2;
4. (a) int counter = 3; 210
while (counter--> 0)
cout << counter << " ";
(b) int counter = 3; 21
while (--counter > 0)
cout << counter << " ";

You might also like