1#include <stdio.h>
2
3unsigned long long int factorial(unsigned int i) {
4
5 if(i <= 1) {
6 return 1;
7 }
8 return i * factorial(i - 1);
9}
10
11int main() {
12 int i = 12;
13 printf("Factorial of %d is %d\n", i, factorial(i));
14 return 0;
15}
1#include <stdio.h>
2int sum(int n);
3
4int main() {
5 int number, result;
6
7 printf("Enter a positive integer: ");
8 scanf("%d", &number);
9
10 result = sum(number);
11
12 printf("sum = %d", result);
13 return 0;
14}
15
16int sum(int n) {
17 if (n != 0)
18 // sum() function calls itself
19 return n + sum(n-1);
20 else
21 return n;
22}
23
1#include <stdio.h>
2
3int fibonacci(int i) {
4
5 if(i == 0) {
6 return 0;
7 }
8
9 if(i == 1) {
10 return 1;
11 }
12 return fibonacci(i-1) + fibonacci(i-2);
13}
14
15int main() {
16
17 int i;
18
19 for (i = 0; i < 10; i++) {
20 printf("%d\t\n", fibonacci(i));
21 }
22
23 return 0;
24}