Puzzle 2D6

Fill an integer array with random integers

[E-6] Write a function that fills an array with random integers in the range Low .. High. This is just an easy modification of the previous puzzle.

#include <stdio.h>
#include <stdlib.h>

/* Puzzle D06 -- fill  an array with random integers */
#define COLS 7
#define ROWS 5

/* Generate a random integer  min < = r < = max */ 
int randInt( int min, int max )
{
  return rand()%(max-min+1) + min ;
}

void print2DArray ( int nrows, int ncols, int x[nrows][ncols] )
{
}

void fill2Drandom( int nrows, int ncols, int x[nrows][ncols], int low, int high )
{
}

int main()
{
  int x[ROWS][COLS] ;
  
  /* Fill the array with random integers */
  fill2Drandom( ROWS, COLS, x, 10, 25 );
      
  /* Print the array using our function */
  print2DArray( ROWS, COLS, x  );
  
  printf("\n");
  return 0;
}


Previous Page        Answer         Next Page         Home