lang-bootstrap/05/main.c

36 lines
421 B
C
Raw Normal View History

long factorial(long x) {
2022-02-13 12:24:19 -05:00
if (x == 0) {
return 1;
} else {
return x * factorial(x-1);
}
2022-02-12 21:27:57 -05:00
}
long fibonacci(long x) {
2022-02-13 11:24:30 -05:00
return x > 0 ?
x > 1 ?
fibonacci(x-1) + fibonacci(x-2)
: 1
: 0;
2022-02-12 21:27:57 -05:00
}
2022-02-13 12:24:19 -05:00
long gcd(long a, long b) {
while (a != 0) {
long temp = a;
a = b % a;
b = temp;
}
return b;
}
int main(int argc, char **argv) {
2022-02-13 12:24:19 -05:00
double f = 1;
int exp = 0;
do {
f /= 2;
++exp;
} while (f);
return exp;
2022-02-09 22:44:27 -05:00
}
2022-02-12 21:27:57 -05:00