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

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

View Full Document Right Arrow Icon
for Loops Programming
Background image of page 1

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

View Full DocumentRight Arrow Icon
P102 Prog Fundamentals I: for Loops/Slide 2 The for Statement condition action true false initialization update
Background image of page 2
P102 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;
Background image of page 3

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

View Full DocumentRight Arrow Icon
P102 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;
Background image of page 4
P102 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;
Background image of page 5

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

View Full DocumentRight Arrow Icon
#include <iostream.h> int main() { int listSize, n; int
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

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 Right Arrow Icon
Ask a homework question - tutors are online