{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# for - Programming for Loops P102 Prog Fundamentals I for...

This preview shows pages 1–7. Sign up to view the full content.

for Loops Programming

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
MP102 Prog Fundamentals I: for Loops/Slide 2 The for Statement condition action true false initialization update
MP102 Prog Fundamentals I: for Loops/Slide 3 The for Statement Syntax for ( initialization ; condition ; update ) action How it works: execute initialization statement while condition is true execute action execute update Example: int i; for (i=1; i<=20; i++) cout << "i is " << i << endl;

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
MP102 Prog Fundamentals I: for Loops/Slide 4 N! int number, factorial, n; cout << "Enter positive integer:"; cin >> number; factorial = 1; for (n=1; n<=number; n++) factorial *= n; cout << "The factorial of " << number << " is " << factorial << endl;
MP102 Prog Fundamentals I: for Loops/Slide 5 2 N int number, result, n; cout << "Enter positive integer:"; cin >> number; result = 1; for (n=1; n<=number; n++) result *= 2; cout << "Two raised to the " << number << " power is " << result << endl;

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
int main() { int listSize, n; int value; double sum = 0; double average; cout << "How many input numbers? " << endl; cin >> listSize; cout << " Please enter the " << listSize << " input numbers: " << endl; for (n=listSize; n > 0; n--) { cin >> value;
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 13

for - Programming for Loops P102 Prog Fundamentals I for...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online