1 / 8

Thema: Fibonacci-Zahlen

Leonardo Pisano, genannt Fibonacci geb. vermutlich 1170 – gest. vermutlich 1250 Ort: Pisa. Thema: Fibonacci-Zahlen. Übung 1. Notieren Sie die Seitenlängen der Quadrate, wenn das erste Quadrat eine Seitenlänge 1 hat. Setzen Sie die Folge fort. Erkennen Sie ein Bildungsgesetz?.

merlin
Télécharger la présentation

Thema: Fibonacci-Zahlen

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Leonardo Pisano, genannt Fibonacci geb. vermutlich 1170 – gest. vermutlich 1250 Ort: Pisa Thema: Fibonacci-Zahlen Informatik Kurse 11-13

  2. Übung 1 Notieren Sie die Seitenlängen der Quadrate, wenn das erste Quadrat eine Seitenlänge 1 hat. Setzen Sie die Folge fort. Erkennen Sie ein Bildungsgesetz? Informatik Kurse 11-13

  3. 2-fach-Rekursion Basisfall Lösung 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89 ... fib(n) = fib(n-1) + fib(n-2) mit fib(1) = fib(2) = 1 Informatik Kurse 11-13

  4. Übung 2 Siehe Aufgabenblatt Lösung Informatik Kurse 11-13

  5. Übung 3: Fibonacci-Demo-Programm Lösung: rekursive Methode import info1.*; public class FibonacciDemo{ public static void main(String[] args){ System.out.print("Geben Sie ein Zahl an: "); int a = Console.in.readInt(); System.out.println("fib("+a+") = " + fibonacci(a)); } private static int fibonacci(int a){ } } if (a==1||a==2) return 1; else return fibonacci(a-1)+fibonacci(a-2); Informatik Kurse 11-13

  6. Übung 4 Bauen Sie in das Demoprogramm eine Uhr ein, um den zeitlichen Aufwand bei der Berechnung von Fibonacci-Zahlen zu messen Lösung: import info1.*; public class FibonacciDemoUhr{ public static void main(String[] args){ StoppUhr uhr = new StoppUhr(); System.out.print("Geben Sie ein Zahl an: "); int a = Console.in.readInt(); uhr.starten(); int fib = fibonacci(a); uhr.stoppen(); System.out.println("fib("+a+") = " + fib); System.out.println("Rechendauer: "+ uhr); } private static int fibonacci(int a){ if (a==1||a==2) return 1; else return fibonacci(a-1)+fibonacci(a-2); } Informatik Kurse 11-13

  7. Übung 5 Finden Sie eine grafische Darstellung, aus der man ablesen kann, was in welcher Reihenfolge berechnet wird, wenn man mit unserem Programm Fibonacci-Zahlen bestimmen lässt. Mögliche Lösung: Informatik Kurse 11-13

  8. Übung 6 Finden Sie eine nicht rekursive Methode zur Berechnung der Fibonacci-Zahlen import info1.*; public class FibonacciDemo2 { //gültig bis n= 92 public static void main (String[] args) { System.out.print("a: "); int a = Console.in.readInt(); System.out.println("fib("+a+") = "+fibonacci(a)); } private static long fibonacci(int a){ long fib = 1; for (long fib1 = 1, fib2 = 1, i=3; i <= a; i++){ fib = fib1 + fib2; fib1 = fib2; fib2 = fib; } return fib; } } Typ long, um größere Zahlen berechnen zu können Es können mehrere lokale Variable definiert werden Informatik Kurse 11-13

More Related