Thread: assign values 2d array to normal array

  1. #1
    Registered User
    Join Date
    Sep 2015
    Posts
    6

    assign values 2d array to normal array

    Hey guys,

    I will sketch my problem.


    My simplified code looks like this:

    Code:
    int permutations[3][4] = {
      {number[0], number[1], number[2], number[3]} ,
      {number[0], number[1], number[3], number[2]} ,
      {number[0], number[2], number[1], number[3]} 
    }
    
    void functionx(int number[]) {
      for (i = 0; i < 3; i++) {
    
      /* here is where I have no clue what to do */
    
      if(number[0] * number[1] - number[2] + number[3] == 10l) {
          printf("(%d * %d - %d + %d)", number[0], number[1], number[2], number[3]);
          break;
        }
      
      }
    
    int main(int argc, char*argv[]) {
      int number[4];
      int i;
    
      for(i=0; i<3; i++){
        scanf("%d", &number[i]);
      }
    
      functionx(number);
      
      return 0;
    }
    So in the part from the comment I need some code to assign the vallue of the 2d array to the numbers. Example:

    Input: 1 2 3 4
    Then the first time it goes through the loop in functionx, number[0] has to be 1, number[1] 2, number[3] 3 and number[4] 4. The second time it has to change the place of number[3] and number[4] etcetera.

    How can I achieve this?

    I hope the idea is clear.

    Kind regards,
    Gertjan

  2. #2
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,738
    There is a major flaw with your global array, "permutations". You should declare and define it inside "functionx()" instead, and use that in your for loop. Why have you put it there if you don't know how to use it? Is this code yours, or are you simply asking from us to do your assignment?
    Devoted my life to programming...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How do I assign values to elements of a 2D array?
    By Karyumi in forum C Programming
    Replies: 9
    Last Post: 06-21-2012, 02:48 PM
  2. Assign values to array of structures
    By rlesko in forum C++ Programming
    Replies: 8
    Last Post: 12-12-2010, 03:31 PM
  3. Assign an arrays values to another array
    By laczfinador in forum C Programming
    Replies: 3
    Last Post: 05-06-2009, 07:46 AM
  4. Trying to assign array values to another array
    By edhc44 in forum C++ Programming
    Replies: 10
    Last Post: 02-01-2008, 10:26 PM
  5. 3-d array assign string values
    By WaterNut in forum C++ Programming
    Replies: 8
    Last Post: 07-01-2004, 12:02 AM