Question

please help with this c++ question! Write a function that returns a dynamic array, of size...

please help with this c++ question!

Write a function that returns a dynamic array, of size n, composed of sequential odd integers starting from 1: 1,3,5,7, etc..

int* odd_array(int n) {

0 0
Add a comment Improve this question Transcribed image text
Answer #1
int* odd_array(int n) {
    int* arr = new int(n);
    int value = 1, i = 0;
    while(i<n){
        arr[i] = value;
        value += 2;
        i++;
    }
    return arr;
}
Add a comment
Know the answer?
Add Answer to:
please help with this c++ question! Write a function that returns a dynamic array, of size...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C++ question. Please help, thank you! Write a function called averageOdd that returns the average of...

    C++ question. Please help, thank you! Write a function called averageOdd that returns the average of all of the odd numbers in a 2-Dimensional array with 3 columns. If no odd numbers are present, it should return a result of 0. Excessively long solutions that use more than 15 lines of code may lose points. For example, a program that uses the function averageOdd follows: int main() { int data[2][3] = {{3, 1, 4} , {2, 7, 1}}; cout <<...

  • Given an array and a starting position write a function replaceFromN, that takes an integer array...

    Given an array and a starting position write a function replaceFromN, that takes an integer array 'array', the size of the array size and a starting positions 'n' as parameters and replaces the elements starting from that index onward with the sequence 1,2,3,... The function returns nothing. void replaceFromN(int array[], int size, int n) For example, given array= {15,12,4,9,2,3} n =2 the function should modify array to be {15,12,1,2,3,4}

  • Write a C++ function, smallestIndex, that takes as parameters an int array and its size and...

    Write a C++ function, smallestIndex, that takes as parameters an int array and its size and returns the index of the first occurrence of the smallest element in the array. To test your function, write a main that prompts a user for a list of 15 integers and outputs the index and value of the first occurrence of the smallest value. The program should print out Enter 15 integers: The position of the first occurrence of the smallest element in...

  • Write a function that takes an array of integers as an argument and returns a value...

    Write a function that takes an array of integers as an argument and returns a value based on the sums of the even and odd numbers in the array. Let X = the sum of the odd numbers in the array and let Y = the sum of the even numbers. The function should return X – Y The signature of the function is: int f(int[ ] a) Examples if input array is return {1} 1 {1, 2} -1 {1,...

  • Write a C function  f such that … function  f accepts, as input, … a two-dimensional array of...

    Write a C function  f such that … function  f accepts, as input, … a two-dimensional array of integers in which each row has three columns the number of rows in the array function  f returns the sum of the odd integers in the given array of integers and returns zero if there are no odd integers in the array COMPILER STACK TRACE None PROGRAM EXECUTION STACK TRACE None COMPILER COMMAND LINE ARGUMENTS -lm INPUT OF THE TEST CASE 1 #define NUM_ROWS 5...

  • PLEASE write in C Language, ( you can use array, recursive function, Pointers, Dynamic call by re...

    PLEASE write in C Language, ( you can use array, recursive function, Pointers, Dynamic call by refernce, Structure) a) 70 marks] Write a program that Sorts a given integer array via Selection Sort obtained by rotation around 3. Searches for a key point in the rotated array in O(logn) time, where the rotation Rotates the sorted array around a random point, e.g., 1 2 345->34512 is point is known in advance. ts above by first finding the unknown rotation point...

  • In c++ 1. Write a function named findTarget that takes three parameters - numbers: an array...

    In c++ 1. Write a function named findTarget that takes three parameters - numbers: an array of integers size: an integer representing the size of array target: a number The function returns true if the target is inside the array and false otherwise 2. Write a function min Valve that takes two parameters: myArray an array of doubles - size: an integer representing the size of array The function returns the smallest value in the array 3 Wrile a funcion...

  • USING C++: Write a function that given a 2D dynamic array of integers, will return the...

    USING C++: Write a function that given a 2D dynamic array of integers, will return the number of elements whose absolute value is smaller than a given value x. The function should take as arguments (in this order): a pointer to the array (i.e., 2D dynamic array) the number of rows the number of columns the given value The function should return the number of elements smaller in absolute value than epsilon E.g. if A={{0.2, -0.1, 3.4},{4.4, 0, -2}} and...

  • USING C++ and PYTHON Please Help me: 1. Write a function that takes in an array...

    USING C++ and PYTHON Please Help me: 1. Write a function that takes in an array of integers (and the size of the array in the C/C++ version). The function will reverse the array of integers and return the reversed array. Print the array that is returned from the function. How you "return" the array is up to you, but do not overwrite the original array. Note: in Python, the term list is more appropriate, see https://docs.python.org/3.5/tutorial/datastructures.html a) Example input:...

  • (C++) Write a function that accepts an int array and the array’s size as arguments. The function...

    (C++)Write a function that accepts an int array and the array’s size as arguments.The function should create a new array that is twice the size of the argument array.The function should copy the contents of the argument array to the new array, and initialize the unused elements of the second array with 0.The function should return a pointer to the new array.Demonstrate the function by using it in a main program that reads an integer N (that is not more...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT