Question

Given the just the first value, generate the next seven terms of the sequences like 1,...

Given the just the first value, generate the next seven terms of the sequences like 1, 11, 21, 1211,
111221, 312211, 13112221, 1113213211. Write the program in C++.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

C++ Program:

#include <iostream>

#include <bits/stdc++.h>

using namespace std;

string series(int n)

{

if (n==1)

return "1";

if (n==2)

return "11";

string s="11";

for (int i=3;i<=n;i++)

{

s+='$';

int l=s.length();

int count=1;

string temp = "";

for (int j=1;j<l;j++)

{

if (s[j]!=s[j-1])

{

temp+=count+'0';

temp+= s[j-1];

count = 1;

}

else count++;

}

s=temp;

}

return s;

}

int main()

{

for(int n=1;n<=8;n++)

cout <<series(n) << endl;

return 0;

}

if you like the answer please provide a thumbs up.

Add a comment
Know the answer?
Add Answer to:
Given the just the first value, generate the next seven terms of the sequences like 1,...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
Active Questions
ADVERTISEMENT