Puzzle DB13


Compute the sum of the absolute value of the difference between each array element and its index.

[E-8]Write a function that, for each element a[j], adds |a[j]-j| to a sum. Use an array of integers. Typical output:

  -3   -2   -1    0    1    2    3    4    5    6

sum = 30


Answer         Next Page         Previous Page Home