CSC 105



CSC 112

Fall 2003

Project5

20 points

Due April 23rd

Submit your printed script file on or before the due date with your name, project number, and date in the header.

Part 1:

Using arrays write a C++ program that uses a for loop to initialize each element in an array to the square of the index value, and then prints the array.

The output should be as follows:

Result:

Element Square

====== ======

0. 0

1. 1

2. 4

3. 9

4. 16

Part 2:

Using arrays read in a series of numbers from the keyboard and print them in reverse order; that is, if we read in 1 2 3 4, we want to print 4 3 2 1. With a little thought, it should be obvious that we must read all of the numbers before we can begin printing them. This definitely sounds like a problem for an array. So read up to 20 integers and then print them reversed, 5 to a line. When you are satisfied test part 2 with at least 11 numbers.

$ script

$ cat project5_

$ g++ project5_

$ ./a.out

$ cat project5_

$ g++ project5_

$ ./a.out

$ crtl d

$ br165 typescript

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download