// -------------------------------- Fibonacci.cs ---------------------------------- \\
public class Fibonacci
{
static void Main(string[] args)
{
int vor, vorvor, curr, i ;
// Aufgabe 1
vorvor = 0; //0
vor = 1; //1
Console.WriteLine("fibo(0) = 0") ;
Console.WriteLine("fibo(1) = 1") ;
for(i=2; i<47; i++) // int geht bis 46 einschließlich, long bis 92 einschl.
{
curr = vorvor + vor ;
Console.WriteLine("fibo("+i+") = "+curr) ;
vorvor = vor;
vor = curr;
}
// Aufgabe 2
Console.WriteLine() ;
vorvor = 0; //0
vor = 1; //1
for(i=2; i<22; i++)
{
curr = vorvor + vor ;
Console.WriteLine("fibo("+i+") / fibo("+(i-1)+") = " + (double)curr/vor) ;
vorvor = vor;
vor = curr;
}
Console.WriteLine("Konstante des goldenen Schnitt : " + (1+Math.sqrt(5))/2 );
// Aufgabe 3
Console.WriteLine() ;
double summe=0 ;
vorvor = 1; //1
vor = 1; //2
for(int i=3; i<30; i++)
{
curr = vorvor + vor ;
summe += 1.0/(vorvor*curr) ;
vorvor = vor;
vor = curr;
}
Console.WriteLine("summe = " + summe );
} // end Main
} // end class
Die ersten 47 der Fibonaccizahlen
fibo(0) = 0
fibo(1) = 1
fibo(2) = 1
fibo(3) = 2
fibo(4) = 3
fibo(5) = 5
fibo(6) = 8
fibo(7) = 13
fibo(8) = 21
fibo(9) = 34
fibo(10) = 55
fibo(11) = 89
fibo(12) = 144
fibo(13) = 233
fibo(14) = 377
fibo(15) = 610
fibo(16) = 987
fibo(17) = 1597
fibo(18) = 2584
fibo(19) = 4181
fibo(20) = 6765
fibo(21) = 10946
fibo(22) = 17711
fibo(23) = 28657
fibo(24) = 46368
fibo(25) = 75025
fibo(26) = 121393
fibo(27) = 196418
fibo(28) = 317811
fibo(29) = 514229
fibo(30) = 832040
fibo(31) = 1346269
fibo(32) = 2178309
fibo(33) = 3524578
fibo(34) = 5702887
fibo(35) = 9227465
fibo(36) = 14930352
fibo(37) = 24157817
fibo(38) = 39088169
fibo(39) = 63245986
fibo(40) = 102334155
fibo(41) = 165580141
fibo(42) = 267914296
fibo(43) = 433494437
fibo(44) = 701408733
fibo(45) = 1134903170
fibo(46) = 1836311903
Die Quotienten, die sich dem goldenen Schnitt nähern
fibo(2) / fibo(1) = 1.0
fibo(3) / fibo(2) = 2.0
fibo(4) / fibo(3) = 1.5
fibo(5) / fibo(4) = 1.6666666666666667
fibo(6) / fibo(5) = 1.6
fibo(7) / fibo(6) = 1.625
fibo(8) / fibo(7) = 1.6153846153846154
fibo(9) / fibo(8) = 1.619047619047619
fibo(10) / fibo(9) = 1.6176470588235294
fibo(11) / fibo(10) = 1.6181818181818182
fibo(12) / fibo(11) = 1.6179775280898876
fibo(13) / fibo(12) = 1.6180555555555556
fibo(14) / fibo(13) = 1.6180257510729614
fibo(15) / fibo(14) = 1.6180371352785146
fibo(16) / fibo(15) = 1.618032786885246
fibo(17) / fibo(16) = 1.618034447821682
fibo(18) / fibo(17) = 1.6180338134001253
fibo(19) / fibo(18) = 1.618034055727554
fibo(20) / fibo(19) = 1.6180339631667064
fibo(21) / fibo(20) = 1.6180339985218033
Konstante des goldenen Schnitt : 1.618033988749895