Happy About the progress
This commit is contained in:
+32
@@ -0,0 +1,32 @@
|
||||
#include <cs50.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int fib(int n);
|
||||
|
||||
int main(void)
|
||||
|
||||
{
|
||||
int n = get_int("Fibonacci: ");
|
||||
printf("The %i Fibonacci number is %i\n", n, fib(n));
|
||||
}
|
||||
|
||||
|
||||
// Takes which fibonacci number you want, returns that
|
||||
|
||||
int fib(int n)
|
||||
{
|
||||
// Base Case
|
||||
if (n ==0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (n == 1)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Renursive Case
|
||||
return fib(n-1) + fib(n-2);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user