Thread: array, calling function

  1. #1
    Registered User
    Join Date
    Oct 2007

    array, calling function

    needing help on how to call a function in the main domain area.

    Construct a grid 4 x 4:
    Using only numbers from 1 to 16 (inclusive), fill the table such that:
    No number can be used twice
    The sum of each row is 34
    The sum of each column is 34

    Use a random number generator to obtain numbers between 1 and 15.
    Use modular decomposition to separate the calculation tasks into functions.
    Use #define to create constants such as SIZE and ROWTOTAL.
    The grid should be a 2 dimensional array which is passed by reference into functions.

    i have done the function for random number generator, total sum, and also a chek function to see if the number has already been displayed in the grid or not.

    But what i cant figure out is how i can relate these functions back to the main domain into the array.

    plz help. thnx in advance

  2. #2
    Cogito Ergo Sum
    Join Date
    Mar 2007
    Sydney, Australia
    Firstly it's called the main function, not the main domain area, but I guess it doesn't really matter.

    And then think to yourself what do you need the main function to do?

    I'm guessing you need it to perhaps print the grid? or print error messages or completion messages.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    To pass an array between functions...
    void foo ( int a[4][4] ) {
      if ( a[0][0] == 0 ) {
        a[0][0] = 1;
    int main ( ) {
      int arr[4][4];
      foo( arr );
      return 0;
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 05-13-2011, 08:28 AM
  2. Calling an array into another in a function
    By kroms in forum C Programming
    Replies: 7
    Last Post: 02-28-2009, 09:07 PM
  3. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 11:45 AM
  4. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 07:48 PM
  5. structure vs class
    By sana in forum C++ Programming
    Replies: 13
    Last Post: 12-02-2002, 07:18 AM