Question
in c++ You must implement the function: string get_ap_terms(int a, int d, size_t n); which returns a string containing the first n terms of the
in c++
You must implement the function: string get_ap_terms(int a, int d, size_t n);
which returns a string containing the first n terms of the arithmetic progression (AP) as a sequence of comma-separated values.
Recall that an AP is specified by two terms a and d. The first term is a, and the d is how much you add to each term to get the next term. So the first N terms of the above AP will be:
a, a+d, a+2d, . . . , a+(n-1)*d
Suppose, for example, that a = 1, d = 3, and n = 5. Then this function should return the string
"1,4,7,10,13"
// Return a string of the form n1,n2,n3,... for the given AP. string get_ap_terms (int a, int d, size_t n) {
// TODO - Your code here
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started