C++ MyProgrammingLab Problem: We want to create strings with the following patte
ID: 3562373 • Letter: C
Question
C++ MyProgrammingLab Problem:
We want to create strings with the following patterns for n = 1, 2,3,4,5, ...
a
aba
abacaba
abacabadabacaba
abacabadabacabaeabacabadabacaba ...
Define a recursive function
string pattern(int n)
that returns the correct patterns for n = 1,2,3,4,5 and beyond. (Notice the relationship between a given line and the line before it.)
Don't worry about what happens when n gets big or goes beyond 26, you code will only be tested for small values of n.
Avoid needless inefficiencies.
Explanation / Answer
#include #include using namespace std; // Swap function void SWAP(int &a, int &b) { int temp; temp=a; a=b; b=temp; } void perm(int *array, int start, int end, int &count) { // If we have reached the last two numbers by swapping // then just print the whole array, swap the last 2 numbers // and print the array once again if((end-start) == 1) { for(int i=0;iRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.