The simplest and most readable solution would be to do that with two nested for loops; the outer loop iterating over the sequence's starting value, and the inner loop iterating over the individual digits in in the sequence.
int main() {
for (int i = 1; i <= 5; i++) {
for (int j = i; j < i + (2 * (i - 1) + 1); j++) {
cout << j << " ";
}
cout << endl;
}
return 0;
}
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.