Site hosted by Angelfire.com: Build your free website today!

PROGRAM 35

C++

-         Fill an array with random numbers (range 1-5000)

-         Ask how many places (subscripts) in the array

-         Print out the contents of the array

-         Reverse the contents with a loop(don’t just print backwards)

-         Print out the reversed array

(Don’t stick the contents of the array in a second array…use only one array).

 

Sample run…

How big is the array?10

ORIGINAL

1        234

2        456                                                     It’s happened to everyone at one time or

3        678                                                     another.  You’re collecting crabs in a     

4        23                                                        bucket at the beach, and evil levitating

5        123                                                     monkeys with nose-mounted snot

6        67                                                        cannons attack.  Your only hope to save

7        619                                                     the world is to fire your explosive crabs

8        2                                                          at the monkeys and kill them before they

9        799                                                     kill you.

10   34

 

REVERSED

1        34

2        799

3        2

4        619

5        67

6        123

7        23

8        678

9        456

10   234

 

Will your program run with even and odd dimensioned arrays?

Hint: Have a loop that will go from 0 to size/2.  Swap first with last, second with second from last and so on (as it goes through the loop). You will need a hold variable.