Question

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 ..

Homework Answers

Answer #1
#include <iostream>

using namespace std;

int *arrayOfMultiples(int num, int length);

int main() {
    int *arr = arrayOfMultiples(12, 10);
    for (int i = 0; i < 10; ++i) {
        cout << arr[i] << " ";
    }
    cout << endl;
    delete[] arr;
    return 0;
}

int *arrayOfMultiples(int num, int length) {
    int *arr = new int[length];
    for (int i = 0; i < length; ++i) {
        arr[i] = num*(i+1);
    }
    return arr;
}

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
have a java application need to create an application which is able to do some analysis...
have a java application need to create an application which is able to do some analysis on temperature data stored in a data file. You will be given the “temperatures.dat” data file which contains the data you must analyze. The analysis you’ll need to do is: Total number of data points Find coldest temperature Find warmest temperature Find average temperature Find the frequency of each temperature Find the most frequent temperature Find the least frequent temperature All classes must be...
Student Grades Student Test Grade 1 76 62 2 84 90 3 79 68 4 88...
Student Grades Student Test Grade 1 76 62 2 84 90 3 79 68 4 88 84 5 76 58 6 66 79 7 75 73 8 94 93 9 66 65 10 92 86 11 80 53 12 87 83 13 86 49 14 63 72 15 92 87 16 75 89 17 69 81 18 92 94 19 79 78 20 60 71 21 68 84 22 71 74 23 61 74 24 68 54 25 76 97...
This dataset contains consumer responses indicating the number of times they had to send their product...
This dataset contains consumer responses indicating the number of times they had to send their product for repair and their satisfaction with the repair process. Create a graph which can be used to visually demonstrate the relationship between the two columns of data. Ensure that the chart is professional with appropriate titles, axis labels, etc. Note any observations you see in your visualization (type these as sentences directly into an Excel cell(s)). Sample Satisfaction Rating Repair Requests 1 63% 13...
* Create a function that takes in the length of two sides of a triangle and...
* Create a function that takes in the length of two sides of a triangle and returns an array of all integers that could be the length of the third side. * Note: The sum of two sides of a triangle is always greater than the third. */ exports.default = (firstSide, secondSide) => { // Your code goes here. }; const triangleSideRanges = require('./question').default; console.log(triangleSideRanges(3, 4)); // Expected Output:[ 2, 3, 4, 5, 6 ] console.log(triangleSideRanges(11, 7)); // Expected Output:[5,...
Question 2: Write a C program that read 100 integers from the attached file (integers.txt) into...
Question 2: Write a C program that read 100 integers from the attached file (integers.txt) into an array and copy the integers from the array into a Binary Search Tree (BST). The program prints out the following: The number of comparisons made to search for a given integer in the BST And The number of comparisons made to search for the same integer in the array Question 3 Run the program developed in Question 2 ten times. The given values...
A business analyst wants to know if a new website design compared to an old website...
A business analyst wants to know if a new website design compared to an old website design is showing increased page views per visit. Two different samples of customers are randomly sent to one of two different websites, offering the same products, but with different designs. Is there a difference in average page views between the new and old website design? Use data from "website" sheet in excel. Which of the following was the p-value you used for this statistical...
Many standard statistical methods that you will study in Part II of this book are intended...
Many standard statistical methods that you will study in Part II of this book are intended for use with distributions that are symmetric and have no outliers. These methods start with the mean and standard deviation, x and s. For example, standard methods would typically be used for the IQ and GPA data here data215.dat. (a) Find x and s for the IQ data. (Round your answers to two decimal places.) s= Here are the numbers obs gpa iq gender...
Given here are data for a dependent variable and four potential predictors. y x1 x2 x3...
Given here are data for a dependent variable and four potential predictors. y x1 x2 x3 x4 x5 96 8 60 2.4 48 51 73 6 64 2.1 42 43 108 2 76 1.8 34 20 124 5 74 2.2 11 14 82 6 50 1.5 61 29 89 9 57 1.6 53 22 76 1 72 2 72 38 109 3 74 2.8 36 40 123 2 99 2.6 17 50 125 6 81 2.5 48 55 101 2...
Using the accompanying Student Grades​ data, construct a scatter chart for midterm versus final exam grades...
Using the accompanying Student Grades​ data, construct a scatter chart for midterm versus final exam grades and add a linear trendline. What is the​ model? If a student scores 7878 on the​ midterm, what would you predict her grade on the final exam to​ be? Student Midterm Final Exam 1 75 64 2 85 91 3 80 68 4 88 83 5 76 60 6 67 80 7 78 74 8 95 94 9 67 61 10 93 87 11...
And need to be writing in C++ language Programm need to start with   #include<fstream> Prepare a...
And need to be writing in C++ language Programm need to start with   #include<fstream> Prepare a text file data_in.txt with the following information (highlight the piece of text below with numbers and copy it to a text file): 54, 70, 75, 63, 17, 59, 87, 16, 93, 81, 60, 67, 90, 53, 88, 9, 61, 8, 96, 98, 12, 34, 66, 76, 38, 55, 58, 27, 92, 45, 41, 4, 20, 22, 69, 77, 86, 35, 19, 32, 49, 15,...