Εισαγωγή στον Προγραμματισμό - Ακ. έτος 2024-25 (CEID_22Υ103)
Fibonacci: A Tale of Code and Curiosity (by NotebookLM)
Πέμπτη, 17 Οκτωβρίου 2024 - 5:53 μ.μ.
- από τον χρήστη Θραμπουλίδης ΚλεάνθηςThe lecture hall buzzed with anticipation. Professor Thramboulidis had just set a new challenge: write a program to generate the Fibonacci sequence. The air crackled with the quiet tapping of keyboards as students started to work.
Amongst them was Alex, a bright-eyed student with a thirst for knowledge. The Fibonacci sequence, a series where each number was the sum of the two preceding ones, fascinated him. He'd seen its patterns in nature, from the spiral of seashells to the arrangement of sunflower seeds. Now, he was tasked with bringing this mathematical marvel to life through code1.
Alex began by sketching a simple representation of the process. He drew an ellipse, labelling it "Display Fibonacci Sequence". On one side, he noted the input: "Number of Terms". On the other, he marked the output: "1st Term, 2nd Term..."1. This abstract depiction helped him visualise the flow of data and identify the initial variables he'd need2.
Professor Thramboulidis had emphasised a structured approach to program development. Alex diligently followed the steps: first, an abstract representation of the process; then, a clear textual description; finally, the translation into C code3. He wrote down the steps in plain English, ensuring that each action led logically to the next4. He imagined himself as the computer, meticulously following instructions to ensure the desired outcome3.
The first version of his program, FibonacciNumbersV1, took shape. He declared variables to store the number of terms, the first term, the second term, and the current term5. He used a 'for' loop to iterate through the sequence, calculating and displaying each term as it was generated6. He tested the code, tweaking it until it faithfully reproduced the Fibonacci sequence6.
But Alex's curiosity wasn't satisfied. What if he wanted to store the entire sequence, not just print it term by term? Professor Thramboulidis had introduced the concept of arrays, collections of elements of the same data type stored in contiguous memory locations7. Alex saw the potential.
He envisioned FibonacciNumbersV2, a program that would use an array to hold the entire sequence. He declared a new variable, 'fbNumber', as an array of integers8. He modified his code, using the 'for' loop to calculate each term and store it in the array9. Finally, he added code to display the entire sequence once all the terms were calculated.
As he ran the program, watching the Fibonacci numbers neatly displayed on the screen, Alex felt a surge of satisfaction. He'd not only accomplished the task, but had also explored new coding concepts and deepened his understanding of the Fibonacci sequence. His code was a testament to his curiosity and the power of structured programming, a testament to the beauty of bringing mathematical concepts to life through the magic of code.
Σχόλια (0)