Assignment 5

Due 11/25/2004

 

Since many students still seem to have problems with loops, I decide to give a relatively simple programming assignment on loops. Copy this file to your PC and insert code to solve the following problems:

 

5.1.        Compute and print out the product of a[i].

5.2.        Compute and print out the sum of a[i] for all even i.

5.3.        Compute and print out the sum of a[i] for all odd i.

5.4.        Compute and print out the sum of all positive a[i].

5.5.        Compute and print out the sum of all negative a[i].

5.6.        Compute and print out the sum of a[i] up to the first negative a[i]

5.7.        Print the number of positive a[i]’s.

5.8.        Print the number of positive a[i]’s where i is even.

5.9.        Find and print out the largest a[i].

5.10.    Find and print out the largest a[i]+a[i+1], i=0,1,...,8.

5.11.    Devise another loop exercise.

5.12.    Devise yet another loop exercise.

 

Your program should answer ALL 12 problems in one shot.

 

Extra point problem:

5.13.    Write a program to read in a number and store it as a 32-bit integer. Print this number out in binary representation. For example, reading in 123456789 will produce 0000 0111 0101 1011 1100 1101 0001 0101.

 

Turn in your assignment to http://140.127.194.140. The deadline is midnight, Nov. 25, 2004. Once again, do not cheat.