Merge pull request #27 from Max285/master

Add 2 more algorithms (Fibonacci and Factorial)
This commit is contained in:
Praveen 2017-08-08 13:47:27 +05:30 committed by GitHub
commit fd9b1c44e4
2 changed files with 39 additions and 0 deletions

20
fat.c Normal file
View File

@ -0,0 +1,20 @@
#include <stdio.h>
int fat(int number){
if (number == 1)
return 1;
else
return number*fat(number-1);
}
int main(){
int number;
//Asks the factorial of the number n
printf("Number: ");
scanf("%d", &number);
printf("%d\n", fat(number));
return 0;
}

19
fib.c Normal file
View File

@ -0,0 +1,19 @@
#include <stdio.h>
//Fibonnacci function
int fib(int number){
if(number==1||number==2) return 1;
else return fib(number-1)+fib(number-2);
}
int main(){
int number;
//Asks for the number that is in n position in Fibonnacci sequence
printf("Number: ");
scanf("%d", &number);
printf("%d \n", fib(number));
return 0;
}