O'Reilly logo

Essential C++ by Stanley B. Lippman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

1.5. How to Use Arrays and Vectors

Following are the first eight elements from six numerical sequences:

Fibonacci:  1, 1, 2, 3, 5, 8, 13, 21 
Lucas:      1, 3, 4, 7, 11, 18, 29, 47 
Pell:       1, 2, 5, 12, 29, 70, 169, 408 
Triangular: 1, 3, 6, 10, 15, 21, 28, 36 
Square:     1, 4, 9, 16, 25, 36, 49, 64 
Pentagonal: 1, 5, 12, 22, 35, 51, 70, 92 

Our program must display a pair of elements from a sequence and allow the user to guess the next element. If the user guesses right and wishes to continue, the program then displays a second pair of elements, then a third, and so on. How might we do that?

If succeeding element pairs are taken from the same sequence, the user, recognizing one pair, recognizes them all. That is not very interesting. So we’ll pick an element ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required