Search⌘ K
AI Features

Challenge: Sequences and Loops

Explore how to print number sequences using for loops in C++, including multiples of ten, odd numbers, and complex arithmetic sequences. Learn to implement loops effectively to solve coding challenges and prepare for efficient algorithm design.

Printing number sequences using loops

In this lesson, let’s practice what we’ve learned so far with a few coding challenges.

Print the following number sequences using the for loop.

Multiples of 10

Your code should print the following sequence:

10 20 30 40 50 60

Good luck!

C++
{
limit=6;
// Add your code here
}

Congratulations! Give yourself a round of applause.

In case you’re stuck, go over the solution review in the next lesson.

Odd sequence

Your code should print the following sequence:

1 3 5 7 9 11  

Good luck!

C++
/*
This program should print the above number sequence
till limit, where limit is equal to 11
*/
{
int limit = 11;
// Add code here
}

Congratulations! Give yourself a round of applause.

In case you’re stuck, go over the solution review in the next lesson.

Arithmetic sequence

Your code should print the following sequence:

1 1 3 6 5 11 7 16

Good luck!

If you look closely, there are actually two sequences starting from 1, but the change factor is different.

C++
/*
This program should print the above number sequence
*/
{
int first = 1;
int second = 1;
// Add code here
}

Congratulations! Give yourself a round of applause.

In case you’re stuck, go over the solution review in the next lesson.