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++
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
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.
Part 3: Call your program by the name: "program_003_store_first_1000_primes_in_an_ARRAY". This program must create an array of...
Part 3: Call your program by the name: "program_003_store_first_1000_primes_in_an_ARRAY". This program must create an array of integers, of size 1000. Then, it must store the first 1000 prime numbers in the array. Then, it must print out the contents of the array. C Programming Language
Create a comparison chart among Array, Struct and Class.(in terms of c++)
Create a comparison chart among Array, Struct and Class.(in terms of c++)
In c++, use nested loops to print a matrix with all the even numbers from 1...
In c++, use nested loops to print a matrix with all the even numbers from 1 to 80 displayed in 5 rows and 8 columns.