summaryrefslogtreecommitdiff
path: root/05/main.c
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2022-02-13 12:24:19 -0500
committerpommicket <pommicket@gmail.com>2022-02-13 12:24:19 -0500
commit70523ba1bbfe206030916c2bc502c0466d064e65 (patch)
tree11dc2a00e4eefc76bcb307fe575237cd648402f6 /05/main.c
parentf6ee9bfa664430f27fef26e62dfe084c051f58fa (diff)
if, while, do
Diffstat (limited to '05/main.c')
-rw-r--r--05/main.c45
1 files changed, 21 insertions, 24 deletions
diff --git a/05/main.c b/05/main.c
index 9b4059f..572a4fd 100644
--- a/05/main.c
+++ b/05/main.c
@@ -1,6 +1,9 @@
long factorial(long x) {
- return x > 0 ? x * factorial(x - 1)
- : 1;
+ if (x == 0) {
+ return 1;
+ } else {
+ return x * factorial(x-1);
+ }
}
long fibonacci(long x) {
@@ -11,28 +14,22 @@ long fibonacci(long x) {
: 0;
}
+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) {
- float f = 3.7;
- int i = 37;
- f--;
- ++i;
- --f;
- ++f;
- f++;
- --i;
- f--;
- ++i;
- --f;
- ++f;
- f++;
- --i;
- f--;
- ++i;
- --f;
- ++f;
- f++;
- --i;
-
- return f;
+ double f = 1;
+ int exp = 0;
+ do {
+ f /= 2;
+ ++exp;
+ } while (f);
+ return exp;
}