Thread: Manipulating Array Values

  1. #1
    Registered User
    Join Date
    Aug 2007
    Posts
    10

    Manipulating Array Values

    I'm having trouble figuring out how to manipulate two arrays. The arrays are listed below.

    double z1[2];
    double z2[2];
    z1[0] = a;
    z1[1] = b;
    z2[0] = c;
    z2[1] = d;

    *where a,b,c, & d are user inputs. I need to do different operations as separate functions (i.e. adding, subtracting, dividing, multiplying) and then output the results into a separate array. Any help would be greatly appreciated.

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    Sorry, I don't understand what your end goal is. You need to write functions to perform mathematical operations on arrays? Can you be more specific please?

  3. #3
    Registered User
    Join Date
    Aug 2007
    Posts
    10

    reply

    Yes-to clarify...if I have an array
    Code:
      {a,b} and an array {c,d} I need to write a function to
    
    (a+c) + (b+d)
    Thanks for your help.

  4. #4
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    OK, so what you mean is that adding one array with another array is defined as adding their i+j-th elements together?

    ie.

    Code:
    Array One: [1, 2, 3]
    Array Two: [2, 1, 3]
    
    Array One + Array Two: [3, 3, 6]

  5. #5
    Registered User
    Join Date
    Feb 2006
    Posts
    8
    You just access them as you wrote:
    a = z1[0]
    b = z1[1]
    c = z2[0]
    d = z2[1]

  6. #6
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    OK, so you need a loop to go through each element if I'm understanding this right. This is trivial.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 11-26-2008, 10:25 AM
  2. Replies: 2
    Last Post: 11-19-2008, 02:36 PM
  3. Class Template Trouble
    By pliang in forum C++ Programming
    Replies: 4
    Last Post: 04-21-2005, 04:15 AM
  4. Merge sort please
    By vasanth in forum C Programming
    Replies: 2
    Last Post: 11-09-2003, 12:09 PM
  5. Duplicate values in Array
    By TONYMX3 in forum C++ Programming
    Replies: 2
    Last Post: 01-30-2002, 03:57 PM