際際滷

際際滷Share a Scribd company logo
// include the library for print menssages at console
#include <stdio.h>
// Author: German Augusto Niebles Alvarez
// version 1.0
// Created on 2016/12/17
// C Program which prints the six first fibonacci numbers
// define fibonacci function
void oneFibonacciSecuence()
{
int maxNumero;
int unFibo1;
int unFibo2;
int unCounter;
// store value for counter, upper limit of the loop
maxNumero = 6;
// init counter in 2 for the firt two fibonnaci numbers
unCounter = 2;
printf("The first 6 fibonacci numbers aren");
// init first fibonacci number
unFibo1 = 0;
// init second fibonacci number
unFibo2 = 1;
printf("%unFibo1", unFibo1);
printf("n");
// make a loop for calculate next four fibonacci numbers
while (unCounter<=maxNumero){
printf("%unFibo2" , unFibo2);
printf("n");
// update next fibo number 2 in secuence
unFibo2 = unFibo1 + unFibo2;
// calculate net fibo number 1 in secuence
unFibo1 = unFibo2 - unFibo1;
unCounter = unCounter + 1;
} // end while
} // end function
// Main program
int main()
{
// call fibonacci function
oneFibonacciSecuence();
return 0;
} // end main

More Related Content

Fibonacci surce code

  • 1. // include the library for print menssages at console #include <stdio.h> // Author: German Augusto Niebles Alvarez // version 1.0 // Created on 2016/12/17 // C Program which prints the six first fibonacci numbers // define fibonacci function void oneFibonacciSecuence() { int maxNumero; int unFibo1; int unFibo2; int unCounter; // store value for counter, upper limit of the loop maxNumero = 6; // init counter in 2 for the firt two fibonnaci numbers unCounter = 2; printf("The first 6 fibonacci numbers aren"); // init first fibonacci number unFibo1 = 0; // init second fibonacci number unFibo2 = 1; printf("%unFibo1", unFibo1); printf("n"); // make a loop for calculate next four fibonacci numbers while (unCounter<=maxNumero){ printf("%unFibo2" , unFibo2); printf("n"); // update next fibo number 2 in secuence unFibo2 = unFibo1 + unFibo2; // calculate net fibo number 1 in secuence unFibo1 = unFibo2 - unFibo1; unCounter = unCounter + 1; } // end while } // end function // Main program int main() { // call fibonacci function oneFibonacciSecuence(); return 0; } // end main