Presentation is loading. Please wait.

Presentation is loading. Please wait.

11/10/2016CS150 Introduction to Computer Science 1 Last Time  We covered “for” loops.

Similar presentations


Presentation on theme: "11/10/2016CS150 Introduction to Computer Science 1 Last Time  We covered “for” loops."— Presentation transcript:

1 11/10/2016CS150 Introduction to Computer Science 1 Last Time  We covered “for” loops

2 21/10/2016CS150 Introduction to Computer Science 1 Localized Declarations for (int i = 0; i < n; i++) cout << i << endl; i is declared ONLY in the loop

3 31/10/2016CS150 Introduction to Computer Science 1 Rewrite using a while loop for (i = 5; i < 10; i+= 2) cout << i; What does this output?

4 41/10/2016CS150 Introduction to Computer Science 1 Formatting Output  How can we generate this output? Fahrenheit Celsius 32.000 0.000 33.000 0.556 34.000 1.111 35.000 1.667 36.000 2.222

5 51/10/2016CS150 Introduction to Computer Science 1 The Program float F,C; F = 32.0; cout << fixed << setprecision(3); cout << "Fahrenheit"; cout << "Celsius" << endl; while (F <= 212.0) { C = (5.0/9.0)*(F - 32); cout << setw(10) << F << setw(12) << C << endl; F += 1; }  You must have #include

6 61/10/2016CS150 Introduction to Computer Science 1 Programs  Write a program that will print the sum of the odd integers between 1 and 50 inclusive. Write one program using a while and the other using a for loop.

7 71/10/2016CS150 Introduction to Computer Science 1 Program  Write a program that inputs 50 numbers and outputs the largest and the smallest number

8 81/10/2016CS150 Introduction to Computer Science 1 Conditional Loops  Loops that execute until some condition is met  Includes more than counting  Use while loops

9 91/10/2016CS150 Introduction to Computer Science 1 Program  Write a flag controlled loop that continues to read pairs of integers until it reads a pair with the property that the first integer is evenly divisible by the second


Download ppt "11/10/2016CS150 Introduction to Computer Science 1 Last Time  We covered “for” loops."

Similar presentations


Ads by Google