I Haz Codes

Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors
Menu
Problem solving – counter

Learn

How can counter controlled loops be used to solve basic problems? In this lesson we will look at how you can apply basic problem solving skills to loop problems. I give you a three step solution to using counter controlled loops.

  1. Write the code to be repeated.
  2. Write the counter controlled loop.
  3. Combine.

Try

Write a program that will add up the numbers 1 to 100 and then display the answer. The calculation should be 1+2+3+4+5…+98+99+100.

You will need an extra variable called total which starts at 0.

Challenge

The following series of numbers is called the Fibonacci Series (discovered by Leonardo Pisano Bigollo aka Fibonacci).

0,1,1,2,3,5,8,13, 21, 34, 55

Write a program to generate this famous sequence of numbers.

Tasks to try

Challenge task

Comments are closed.

Information