C++C++11C++14C++17Generic ProgrammingLearn C++

Learn To Easily Develop A Fun Fibonacci Number Generator In C++ For Windows

Fibonacci Numbers are sequence numbers called the Fibonacci sequence, and in mathematics, it starts with 0 and 1, and then each number is the sum of the two preceding ones. Fibonacci numbers are strongly related to Golden Ratio. In mathematics, two quantities are in the golden ratio if their ratio is the same as the ratio of their sum to the larger of two quantities. There is Binet’s formula that shows the nth Fibonacci number in terms of n and the golden ratio. It implies that the ratio of two consecutive Fibonacci numbers tends to the golden ratio as n increases.

Basically, we can say formulate that fn = fn-1 + fn-2, for example, we can easily find these Fibonacci Numbers as below;

0+1=1
1+1=2
2+1=3
3+2=5
5+3=8

So we can list these first 20 numbers as 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181,…

Fibonacci numbers are something like showing steps of life growing. The golden ratio is also known as a ratio that mostly human likes in nature. So these numbers and ratios are widely used in art, architecture, music, engineering, nature also has examples of these. It would be nice to calculate these numbers easily and can be used in one of these areas in your applications. 

In programming we can briefly write this Fibonacci function as below;

We can print out all numbers in range as given print_fibonacci_numbers(…) procedure below;

Let’s run this function with C++ Builder in a VCL example ;

  1. Create a new C++ Builder Console (VCL) Application and modify lines as below

2. Hit F9 or press Run button to run your codes. That’s All.

close

Oh hi there 👋
It’s nice to meet you.

Sign up to receive awesome C++ content in your inbox, every day.

We don’t spam! Read our privacy policy for more info.

About author

33+ years of coding with more than 30+ programming languages, mostly C++ on Windows, Android, Mac-OS, iOS, Linux and some other operating systems. Dr. Yilmaz Yoru was born in 1974, Eskisehir-Turkey. He graduated from the department of Mechanical Engineering of Eskisehir Osmangazi University in 1997. One year later he started to work in the same university as an assistant. He received his MSc and PhD degrees from the same department of the same university. He has married and he is a father of a son. Some of his interests are Programming, Thermodynamics, Fluid Mechanics and Artificial Intelligence. He also likes the graphical 2D & 3D design and high-end innovations.
Related posts
C++Introduction to C++Language FeatureLearn C++

How To Use The Comprehensive Form Properties In C++ VCL Apps

C++C++11C++14C++17Introduction to C++Learn C++

This Is How To Add Characters to Wide Strings in Modern C++

C++ComponentsLanguage FeatureLearn C++

How To Create Gorgeous Transparent App Windows With C++

C++C++11C++14C++17Introduction to C++Learn C++

This Is How To Get A Substring of a Wide String in C++

en_USEnglish