Created
May 24, 2020 13:22
-
-
Save chinmaythosar/9c2a08b025ecf17848ea16efe95074f3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Calculating Fibonacci without using any loops in O(n) | |
//No goal in particular just asked for a task. | |
#include<stdio.h> | |
int *arr; | |
int fib(int n); | |
int main(void) { | |
puts("Hello World!"); | |
int n=15; | |
arr=malloc(sizeof(int)*2); | |
arr[0]=1; | |
arr[1]=1; | |
arr[0]= | |
printf("%d",fib(n-2)); | |
free(arr); | |
return 0; | |
} | |
int fib(int n){ | |
if(n==0) | |
return arr[1]; | |
else | |
{ | |
int temp = arr[1]+arr[0]; | |
arr[0]=arr[1]; | |
arr[1]=temp; | |
return fib(n-1); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment