Skip to content

Instantly share code, notes, and snippets.

@javiermontenegro
Last active November 30, 2019 19:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save javiermontenegro/8460dd6a6566d51ba358601bc1a008fb to your computer and use it in GitHub Desktop.
Save javiermontenegro/8460dd6a6566d51ba358601bc1a008fb to your computer and use it in GitHub Desktop.
This gist is a example of fibonacci algorithm in ANSI C
/*********************************************************************
* Filename: C_Fibonacci.Number.c
* Author: Javier Montenegro (javiermontenegro.github.io)
* Copyright: @2019
* Details: this gist is a example of fibonacci algorithm in ANSI C
*********************************************************************/
#include <stdio.h>
#include <time.h>
int fn(int number);
//Fibonnacci function
int fn(int number)
{
if(number==1||number==2) return 1;
else return fn(number-1)+fn(number-2);
}//End fn
int main()
{
int number;
printf("Enter number:\n");
scanf("%d", &number);
printf("------------\n");
clock_t start = clock();
printf("Fibonacci:\n");
printf("%d\n", fn(number));
clock_t end = clock();
double time_spent = (double)(end - start) / CLOCKS_PER_SEC;
printf("\nTime spent: %f\n", time_spent);
return 0;
}//End main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment