Wie man ein C -Programm Fibonacci Folge Rekursiv in der Programmiersprache C geschrieben?
Das C-Programm Sie die Fibonacci- Reihe rekursive Zahl bis n-te Nummer finden
Solution:
- int fib(int n) {
- int i = 0; //Zählvariable
- int a = 0; //Fibonacci Zahl an (i)-ter Stelle
- int b = 1; //Fibonacci Zahl an (i+1)-ter Stelle
- while (i<n) {
- i++;
- a = a^b; b = a^b; a = a^b;
- b = a+b;
- };
- return a;
- }
- int fib_rec(int n) {
- if (n == 0) return 0;
- if (n == 1) return 1;
- return fib_rec(n-1)+fib_rec(n-2);
- }
- int main(void) {
- int n = 0; //Zielstelle
- printf("\nGib ein n ein: ");
- scanf("\n%i",&n);
- printf("Die Fibonacci Zahl an n-ter Stelle ist %i \n", fib(n));
- return 0;
- }
Learn More :
German
- Write the procedure , which is one of a sum , a product and a geometric average in the panel for the NxM elements are located on opposite diagonal and main diagonal . Remind ! Counting only odd elements !
- C Programm zur Berechnung von Umfang und Flächeninhalt verschiedener geomatrischer Figuren
- C -Programm Fibonacci-Folge