Add examples
This commit is contained in:
parent
66586a1427
commit
5d0f86545e
17
example/fibonacci_imp.c
Normal file
17
example/fibonacci_imp.c
Normal file
@ -0,0 +1,17 @@
|
||||
int num = 15;
|
||||
int result = -1;
|
||||
|
||||
if (num < 2)
|
||||
result = num;
|
||||
else {
|
||||
int prev1 = 1;
|
||||
int prev2 = 0;
|
||||
for (int i=2; i < num; i++)
|
||||
{
|
||||
int tmp = prev1;
|
||||
prev1 = prev1 + prev2;
|
||||
prev2 = tmp;
|
||||
};
|
||||
result = prev1+prev2;
|
||||
}
|
||||
result;;
|
8
example/fibonacci_rec.c
Normal file
8
example/fibonacci_rec.c
Normal file
@ -0,0 +1,8 @@
|
||||
int fibo(int n) {
|
||||
if (n <= 1) {
|
||||
return n;
|
||||
} else {
|
||||
return fibo(n - 1) + fibo(n - 2);
|
||||
}
|
||||
}
|
||||
fibo(15);;
|
21
example/primes.c
Normal file
21
example/primes.c
Normal file
@ -0,0 +1,21 @@
|
||||
int is_prime(int num) {
|
||||
if (num <= 1) return 0;
|
||||
for (int i = 2; i * i <= num; i++) {
|
||||
if (num % i == 0) return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int max_prime(int limit) {
|
||||
int prime = 0;
|
||||
|
||||
for (int i = 1; i < limit; i++) {
|
||||
if (is_prime(i)) {
|
||||
prime = i;
|
||||
}
|
||||
}
|
||||
|
||||
return prime;
|
||||
}
|
||||
|
||||
max_prime(250);;
|
13
example/stack_trace.c
Normal file
13
example/stack_trace.c
Normal file
@ -0,0 +1,13 @@
|
||||
int function1(int a) {
|
||||
return a/0;
|
||||
}
|
||||
|
||||
int function2(int b, int c) {
|
||||
return function1(b+c);
|
||||
}
|
||||
|
||||
int main(int x) {
|
||||
return function2(x, 2*x+3)*12;
|
||||
}
|
||||
|
||||
main(3);;
|
Loading…
Reference in New Issue
Block a user