Challenge: Sequences and Loops
Test your problem solving skills in this challenge exercise.
We'll cover the following
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!
{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!
/*This program should print the above number sequencetill 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.
/*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.