My daughter asked a question about the fibonacci formula while studying c++ code a few days ago.
The concept was simply to list rows and columns using loops. Loops can use for, or while.
Oh, of course, if I use recursion, then able to shorten the line, but basically, I used a basic loop to explain the concept.
I'm not familiar with other loops because of my favorate loop is for, but I can't avoid it forever, so I tried it(Since I keep using only one method then suddenly can't remember when I want to use another method lol.).
-> I found good math fibonacci theory web site, here .
Code is here below the link
https://github.com/EunsunKim/My_Cpp_DemoCase/blob/master/fibonacci.cpp
I've created 2 functions for half triangle and full triangle fibonacci result.
if user input is 10;
Half triangle fibonacci is easy. Simply write two for loops to print the result of the fibonacci formula according to the row and column. Staring number is 1
For the whole triangle result, I used a while loop, which I rarely use.
basic concept is like this,
while(i <= row){... i++;}
and I divided 3 sections for empty space, left and right side inside the mail while loop.
I designed it to put the sum result in the very center.
while(space <= row-1){... space++;}
while(left > 0){... left--;} //head from left to middle center
while(right <=1){... right++;} //head from middle center to right