prev

Assignment 2

next
  1. Set up an array of 10 floating point numbers.
  2. Initialize all of the elements of the array to 0.0
  3. Define a function that takes an integer argument, computes the value of x*x + x where x is the value of the integer, and returns the computed vale.
  4. Fill the array with the values that are computed from the function where the value passed to the function is the index of the array.
  5. After the array values have all been calculated. Print the array, one line per value.

The resulting output should look something like the following.

        0.000000
        2.000000
        6.000000
        12.000000
        20.000000
        30.000000
        42.000000
        56.000000
        72.000000
        90.000000
    

Note that you probably will get casting errors in this program. You can ignore them at the moment and so will we. If you want to fix it then you should put (float) before ints that you would like transformed and this will tell the compiler that you intend for it to do the conversion for you.