mirror of https://github.com/TheAlgorithms/C
Merge pull request #27 from Max285/master
Add 2 more algorithms (Fibonacci and Factorial)
This commit is contained in:
commit
fd9b1c44e4
|
@ -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;
|
||||
}
|
|
@ -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;
|
||||
}
|
Loading…
Reference in New Issue