Thread: Vector dynamically allocated.

  1. #1
    Registered User
    Join Date
    Oct 2019
    Posts
    7

    Vector dynamically allocated.

    A vector with n integer elements is given. It is required the return of a new vector, dynamically allocated, that will have in position i the product of all elements in the received vector, except the element in position i.

    I created the vector that receives in elements, but I do not know how to take an element then multiply it with each one less himself, and take the value of the first element in the new vector.
    Example: v[i] = v[i+1] * v[i+2]
    input:
    3
    4 5 6
    output:
    30 24 20

  2. #2
    Registered User
    Join Date
    Aug 2019
    Location
    inside a singularity
    Posts
    302
    Use a pen and paper, write down what you want to do and code it out. Create a function which returns a vector. In the function create a new vector. Add a sensible loop. Add your conditions. Save the values into new vector correctly. Return this new vector.
    "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook, The Wizardry Compiled

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help With Dynamically Allocated Stack
    By ThR1LL in forum C Programming
    Replies: 1
    Last Post: 04-27-2014, 06:37 PM
  2. Dynamically Allocated arrays and MPI
    By DerekC in forum C Programming
    Replies: 3
    Last Post: 03-09-2010, 01:06 PM
  3. Dynamically allocated array
    By dre in forum C Programming
    Replies: 17
    Last Post: 08-13-2009, 06:57 PM
  4. Dynamically allocated memory
    By ^xor in forum Linux Programming
    Replies: 9
    Last Post: 06-28-2005, 11:42 AM
  5. Dynamically allocated matrices
    By Unregistered in forum C++ Programming
    Replies: 5
    Last Post: 10-27-2001, 10:10 PM

Tags for this Thread