You are on page 1of 2

Bi lm thm tun 03

Bi 1. Tm cc li trong cc on m lnh di y:
a. For ( x = 100, x >= 1, x++ )
cout << x << endl;

b. on code sau dng kim tra mt s l s chn hay s l:


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

c. on code sau dng in ra cc s nguyn l triong on t 19 ti 1:


for ( x = 19; x >= 1; x += 2 ) cout << x << endl;

d. on code sau dng in ra cc s nguyn chn trong on t 2 ti nh hn 100:


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

Bi 2. Chng trnh sau in ra kt qu g?


// Exercise 5.7: ex05_07.cpp // What does this program print? #include <iostream> using std::cout; using std::cin; using std::endl; int main() { int x; // declare x int y; // declare y // prompt user for input cout << "Enter two integers in the range 1-20: "; cin >> x >> y; // read values for x and y for ( int i = 1; i <= y; i++ ) // count from 1 to y { for ( int j = 1; j <= x; j++ ) // count from 1 to x cout << '@'; // output @

cout << endl; // begin new line } // end outer for return 0; // indicate successful termination } // end main

Bi 3. Chng trnh sau lm g?


Gi x i = 1, j = 2, k = 3 v m = 2. Mi cu lnh di y in ra g? Cc cp ngoc n c cn thit

cho mi trng hp khng? a. b. c. d. e. f. g. h. i.


cout cout cout cout cout cout cout cout cout << << << << << << << << << ( ( ( ( ( ( ( ( ( i == 1 ) << endl; j == 3 ) << endl; i >= 1 && j < 4 ) << endl; m <= 99 && k < m ) << endl; j >= i || k == m ) << endl; k + m < j || 3 - j >= k ) << endl; !m ) << endl; !( j - m ) ) << endl; !( k > m ) ) << endl;

You might also like