Mathematics 1201: Programming in C Reading and Homework Assignment #1 Prof. Wickerhauser Due 1 September 1999 You are encouraged to collaborate on homework, and to work additional exercises from the indicated problem sections, although the homework grade will be based only on the exercises listed below. Please return your solutions to me by the end of class. LATE HOMEWORK WILL NOT BE ACCEPTED. Read the Preface and Chapter 1 of the textbook. Do Exercises 2, 3, and 5 of Chapter 1. [Exercise 2, p.16] When you run the following program, it should echo back the command line arguments, each on a separate line. Check that it works on your system. #include main( int argc, char **argv ) { while( --argc ) puts( *++argv ); } [Exercise 3, p.16] The following program copies from the standard input to the standard output. Use redirection to copy from one file to another file. What happens if the output and input files are the same? #include main(void) { int Ch; while( ( Ch = getchar( ) ) != EOF ) putchar( Ch ); return 0; } [Exercise 5, p.17] Write a program to compute X to the Nth power for nonnegative integers N. Assume that X to the 0th power is 1. Extra Problems: 1. Write, compile and execute the following computer program: #include main( void ) { int i; for( i=10; i>0; i-- ) printf( "%d...", i ); printf( "blastoff!\n" ); return(0); } Figure out how to print the output of this program. Suggestion: redirect it to a file named ``boom'' and print that. 2. What does the following program do? #include main( int argc, char **argv ) { int i; if( argc<2 ) return(1); i = 0; while( argv[1][i] ) ++i; while( i ) putchar( argv[1][--i] ); putchar('\n'); return(0); } How should it be called to print out the message ``Hello''? Bonus: can you get this program to print the message ``Hi there''? how about ``Hi there!''?.