Question

create an array and fill it in with even numbers. use c++

create an array and fill it in with even numbers. use c++

Homework Answers

Answer #1
#include <iostream>

using namespace std;

int main() {
    int size;
    cout << "Enter size of array: ";
    cin >> size;
    int *arr = new int[size];
    for (int i = 0; i < size; ++i) {
        arr[i] = 2*(i+1);
    }
    cout << "Generated even array is: ";
    for (int i = 0; i < size; ++i) {
        cout << arr[i] << " ";
    }
    cout << endl;
    delete[] arr;
    return 0;
}

Know the answer?
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
Similar Questions
In C++ 1.) Create a function called copyMyArray. It should take in an array and copy...
In C++ 1.) Create a function called copyMyArray. It should take in an array and copy array1 into array2. 2.) Create a vector and fill it with the numbers 1 to 10. Replace the number 3 with the number 3000. Insert the number 5000 between the 5 and 6.
Please, write a loop to print even numbers of an array a with pointers. You can...
Please, write a loop to print even numbers of an array a with pointers. You can use a variable “size” for array size
Create an array that is filled with the numbers 1 to 50. Output the array's contents...
Create an array that is filled with the numbers 1 to 50. Output the array's contents to main. Change all the values to 0 and check that this is the case. Use C++
Develop a python program to - Create a 2D 10x10 numpy array and fill it with...
Develop a python program to - Create a 2D 10x10 numpy array and fill it with the random numbers between 1 and 9 (including 0 and 9). - Assume that you are located at (0,0) (upper-left corner) and want to move to (9,9) (lower-right corner) step by step. In each step, you can only move right or down in the array. - Develop a function to simulate random movement from (0,0) to (9,9) and return sum of all cell values...
C++ program for : 1. Given an array of real numbers and the dimension n (n...
C++ program for : 1. Given an array of real numbers and the dimension n (n is entered from the keyboard). B form an array, each element bi - arithmetic mean of the array elements and excluding ai. 2. Given an array of integers dimension n. Change the array so that all the elements of the module which is not equal to the maximum element of the array, replaced by zero, and equal - unit. 3. Given an array of...
how do i create an array of 65536 elements with random non repeated numbers and it...
how do i create an array of 65536 elements with random non repeated numbers and it is sorted? in java please. thank you
C++ Create an empty vector in main called theVect. Ask the user for a number. Fill...
C++ Create an empty vector in main called theVect. Ask the user for a number. Fill the vector with 10 random numbers that are multiples of that number. So, for instance, if the user says 7, then you need to use a while loop and fill in the vector with any randomly generated number that is num % 7.
JAVA IDE NETBEANS Create a program that will prompt the user to enter 20 numbers using...
JAVA IDE NETBEANS Create a program that will prompt the user to enter 20 numbers using any looping statement. Store it in a 2-dimensional array. Display all the numbers in a table format. Determine which numbers are odd and which numbers are even (include their array index) need some help with codes
Create a function that takes two numbers as arguments (num, length) and returns an array of...
Create a function that takes two numbers as arguments (num, length) and returns an array of multiples of num up to length. Examples: arrayOfMultiples(7, 5) ➞ [7, 14, 21, 28, 35] arrayOfMultiples(12, 10) ➞ [12, 24, 36, 48, 60, 72, 84, 96, 108, 120] arrayOfMultiples(17, 6) ➞ [17, 34, 51, 68, 85, 102] Notes Notice that num is also included in the returned array. Write in C++ language ..
Using import java.util.Random, create a simple java code that populates an array with 10 random numbers...
Using import java.util.Random, create a simple java code that populates an array with 10 random numbers (choosing between a range of 20 to 90) and then outputs the largest number.