No exit yes print 2counter counter counter 1 stop

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: #include <iostream.h> main ( ) { int counter ; for ( counter = 1 ; counter <= 10 ; counter = counter + 1 ) { cout << "2 x " << counter << " = " << 2* counter << "\n“ ; } } Output 2 x1 = 2 2 x 2 = 4 2 x 3 = 6 : : 2 x 10 = 20 Flow chart for the ‘Table’ example Start counter=1 While counter <=10? No Exit yes Print 2*counter Counter = counter + 1 Stop Example: Calculate Table­ Enhanced #include <iostream.h> main ( ) { int number ; int maxMultiplier ; int counter ; maxMultiplier = 10 ; cout << " Please enter the number for which you wish to construct the table “ ; cin >> number ; for ( counter = 1 ; counter <= maxMultiplier ; counter = counter + 1 ) { cout << number <<" x " << counter<< " = " << number * counter << "\n“ ; } } Always think re­use Don’t use explicit constants Increment operator ++ counter ++ ; same as counter = counter + 1; Decrement operator ­­ counter ­­...
View Full Document

This note was uploaded on 01/12/2010 for the course CS CS 201 taught by Professor Dr.naveedmalik during the Spring '09 term at Virtual University of Pakistan.

Ask a homework question - tutors are online