Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Implement a program that contains the following functions. a. A function that co

ID: 3537099 • Letter: I

Question

Implement a program that contains the following functions.


a. A function that computes an arithmetic progression with an initial term a and common difference d, and the number of progressions n, where a, n and d are given as input parameters to the function.


b.      A function which computes a geometric progression with an initial term a and a common ratio r, and the number of progressions n, where a, n and r are given as input parameters to the function.


c.       A function which computes the Fibonacci sequence.

f(0)=0, f(1)=1,

f(n)=f(n-1)+f(n-2) if n>1


d.      A main function which read from the console a, d, r, n computes the values of the three functions and prints the output.

Explanation / Answer

#include<iostream>
#include<math.h>
using namespace std;
void generate_airthmetic(int a, int n,int d)
{
cout << " Airthematic progression is " ;
for(int i=0; i<=n; i++)
{
cout << (a + i*d) << " " ;
}
cout << endl;
}
void generate_geometic(int a, int n,int d)
{
cout << " geomatic progression is " ;
for(int i=0; i<=n; i++)
{
cout << (a* pow(d,i)) << " " ;
}
cout << endl;
}
void generate_fibonacci(int n)
{
int a = 0;
int b = 1;
int c;

cout << " fibonacci sequence is " ;
cout << a << " " << b << " " ;
for(int i=1; i<=n; i++)
{
c = a +b;
a = b;
b = c;
cout << c << " ";
}
cout << endl;
}
int main()
{
int a,n,d,first,r,no;
int total;
cout << " enter values of a,n, d";
cin >> a >> n >> d;
cout << endl;
cout << " enter values of first term and common ratio and number of tersm ";
cin >> first >> no >> r;
cout << endl;
cout << " enter total no of terms in fibnocacci sequence ";
cin >> total;
cout << endl;
generate_airthmetic(a,n,d);
generate_geometic(first,no,r);
generate_fibonacci(total);
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote