int price, profit; for (price = 10; price <= 30; price +=1) {

# int price, profit; for (price = 10; price <= 30; price +=1) {

Télécharger la présentation

## int price, profit; for (price = 10; price <= 30; price +=1) {

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
##### Presentation Transcript

1. int price, profit; for (price = 10; price <= 30; price +=1) { profit = price * (100 – 3 * price); cout << setw(5) << price << setw(10) << profit << endl; }

2. int i; for (i = 10; i >= 0; i = i – 2) cout << i << ‘ ‘;

3. char ltr; for (ltr = ‘A’; ltr <= ‘F’; ltr++) cout << ltr;

4. int i; for (i = 1; i <= 10; ++i) cout << i << “ “;

5. int i; for (i = 5; i > 0; ++i) cout << i << “ “;

6. int i; for (i = 1; i <= 10; ++i) { cout << i << “ “; i += 2; }

7. int i, num, sum = 0; for (i = 0; i <= 4; i++) { cout << “Enter number #” << (i + 1) << ‘ ‘; cin >> num; sum += num; }

8. int i; for (i = 1; i <=3; i++) cout << “Hi “; cout << “there. \n”; cout << “Bye\n”;

9. int j; for (j = 20; j >= 5; j -= 3) cout << j << ‘ ‘;

10. int j; for (j = 20; j >= 5; j += 7) cout << j << ‘ ‘;

11. int sum = 0, j; for (j = 1; j <= 4; j++) { sum += j * j; cout << j << ‘ ‘ << sum << endl; } cout << “done\n”;

12. Fill in the blanks: output: 2 3 5 8 13 21 34 55 int i, sum, j = 1, k = 1; for (i = 1; i <= 8; i++) { __________ = j + k; cout << sum << ‘ ‘; j = k; k = _____; }

13. Fill in the blanks: output: 2^1 = 2 2^2 = 4 2^3 = 8 2^4 = 16 2^5 = 32 2^6 = 64 int j, prod = 1; for (j = 1; _______; ++j) { prod = ______; cout << “2^” << ___ << “ = “ << ____ << endl; }

14. int j, p = 30; for (j = 5; j; --j) { p -= 2; cout << p << ‘ ‘; if (p % 4) cout << “OK”; cout << ‘\n’; }

15. int j, m = 10, p = 20; for (j = 1; j <= 3; j++) { p = m – 2; m = m + p; p += 6; if (m > p) cout << p; else cout << m; cout << endl; } cout << m << ‘ ‘ << p;

16. int row, col; for (row = 1; row < 6; row++) { for (col = 1; col < 11; col++) cout << row << ‘,’ << col << ’\t”; cout << endl; }