DoGy70

Untitled

Mar 28th, 2023
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int factorial(int n) {
  4.  
  5. if(n == 0) {
  6. return 1;
  7. } else {
  8. return n * factorial(n-1);
  9. }
  10. }
  11.  
  12. int fibbonacci(int n) {
  13. if(n == 0){
  14. return 0;
  15. } else if(n == 1) {
  16. return 1;
  17. } else {
  18. return (fibbonacci(n-1) + fibbonacci(n-2));
  19. }
  20. }
  21.  
  22. int main() {
  23. int n = 5;
  24. int i;
  25.  
  26. printf("Factorial of %d: %d\n" , n , factorial(n));
  27. printf("Fibbonacci of %d: " , n);
  28.  
  29. for(i = 0;i<n;i++) {
  30. printf("%d ",fibbonacci(i));
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment