An arithmetic progression (AP) is a sequence of numbers such that the difference between the consecutive terms is constant. For instance, 5, 7, 9, 11, 13, 15,... is an arithmetic progression starting at 5 with common difference of 2. Write a function named arithProg that takes an array size (n), a start value and the difference that returns a dynamically allocated array containing the first n values in the arithmetic progression starting at start, with the provided difference. Write a main function to demonstrate your function. Assume the input will be a size, start value and difference. The output should be the elements of the new array. Be sure to deallocate any dynamically allocated memory! If the input is 523 the output should be 2 5 8 11 14

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

In C++ please and thank you!

**Arithmetic Progression (AP)**

An arithmetic progression (AP) is a sequence of numbers such that the difference between the consecutive terms is constant. For instance, 5, 7, 9, 11, 13, 15, ... is an arithmetic progression starting at 5 with a common difference of 2.

**Task**

Write a function named `arithProg` that takes an array size (n), a start value, and the difference that returns a dynamically allocated array containing the first n values in the arithmetic progression starting at `start`, with the provided difference.

**Instructions**

1. Write a main function to demonstrate your function.
2. Assume the input will be a size, start value, and difference.
3. The output should be the elements of the new array.
4. **Be sure to deallocate any dynamically allocated memory!**

**Examples**

- If the input is:
  ```
  5 2 3
  ```
  The output should be:
  ```
  2 5 8 11 14
  ```

- If the input is:
  ```
  9 1 2
  ```
  The output should be:
  ```
  1 3 5 7 9 11 13 15 17
  ```
Transcribed Image Text:**Arithmetic Progression (AP)** An arithmetic progression (AP) is a sequence of numbers such that the difference between the consecutive terms is constant. For instance, 5, 7, 9, 11, 13, 15, ... is an arithmetic progression starting at 5 with a common difference of 2. **Task** Write a function named `arithProg` that takes an array size (n), a start value, and the difference that returns a dynamically allocated array containing the first n values in the arithmetic progression starting at `start`, with the provided difference. **Instructions** 1. Write a main function to demonstrate your function. 2. Assume the input will be a size, start value, and difference. 3. The output should be the elements of the new array. 4. **Be sure to deallocate any dynamically allocated memory!** **Examples** - If the input is: ``` 5 2 3 ``` The output should be: ``` 2 5 8 11 14 ``` - If the input is: ``` 9 1 2 ``` The output should be: ``` 1 3 5 7 9 11 13 15 17 ```
Expert Solution
Step 1

code:

 

#include<iostream>
using namespace std;
void mainAP(int n, int aa, int cd)
{

int curr;
curr=aa;
for (int i = 1; i <= n; i++)
{ cout << curr << " ";
 curr =curr + cd;
 
}
}
int main()
{
int aa,cd,n;
cout<<"Enter the values=";
cin>>n>>aa>>cd;
 mainAP( n,aa,cd);

 return 0;
}

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Arrays
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education