Professional Documents
Culture Documents
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;
}
State whether the result of each the following expressions is true or false.
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 << " ";