Puzzle DA9


Fill an array with an ascending sequence of random integers

[E-6] Write a function that fills an array with integers, where each integer is larger than its predecessor by a random amount in the range 1..MaxStep. Start the array with a random value between 0 and MaxStep-1. A prototype for the function is:

void fillArrayRandomAscending( int size, int arr[], int maxStep )

Sample output of a main program that tests the function for a MaxStep of 10 is:

   0    6    8   17   23   28   32   41   50   58
  60   69   77   83   87   88   89   93   95   97
 107  112  114  115  116  120  126  132  139  146
 148  155  160  164  165  172  180  189  195  199
 208  216  226  236  242  244  249  252  261  264
 272  281  291  301  308  312  315  318  327  328
 332  333  340  341  342  352  355  358  364  371
 380  388  393  396  404  409  414  424  432  434
 440  444  452  459  465  469  471  474  479  488
 494  504  512  516  518  525  530  531  538  544

This array started out at 0, but it could have started with any value between 0 and 9.



Previous Page        Answer         Next Page         Home