mirror of
https://github.com/TheAlgorithms/C
synced 2024-11-22 05:21:49 +03:00
Merge pull request #27 from Max285/master
Add 2 more algorithms (Fibonacci and Factorial)
This commit is contained in:
commit
fd9b1c44e4
20
fat.c
Normal file
20
fat.c
Normal 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
19
fib.c
Normal 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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user