chap 4 notes 103 - 1 for(k= 2 k<=n k nfact*=k cout<<...

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

View Full Document Right Arrow Icon
103 #include <iostream> using namespace std; int main( void ) { int n, k, nfact; do { cout << "Enter n or 0 to quit : " ; cin >> n; if (n < 0 ) { cout << "Invalid n entered, " ; cout << "try again." << endl; } else if (n> 0 ) { nfact =
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 1 ; for (k= 2 ; k<=n; k++) { nfact*=k; } cout << n << "! = " << nfact <<endl; } } while (n != ); return ; } Combining Control Structures (Example) this for loop calculates the factorial....
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online