void printDottedLine ( ) { cout << "....." << endl ; }
2. Write the definition of a function printLarger , which has two int parameters and returns nothing. The function prints the larger value of the two parameters to standard output on a single line by itself. (For purposes of this exercise, the "larger" means "not the smaller".)
void printLarger ( int a , int b ) { if ( a > b ) cout << a << endl ; else cout << b << endl ; }
3. Write the definition of a function dashedLine , with one parameter, an int . If the parameter is negative or zero, the function does nothing. Otherwise it prints a complete line terminated by a new line character to standard output consisting of dashes (hyphens) with the parameter's value determining the number of dashes. The function returns nothing.
void dashedLine ( int n ) { if ( n <= 0 ) return ; while ( n > 0 ) { cout << '-' ; -- n; } cout << endl; }
No comments:
Post a Comment