diff options
author | pommicket <pommicket@gmail.com> | 2022-02-13 12:24:19 -0500 |
---|---|---|
committer | pommicket <pommicket@gmail.com> | 2022-02-13 12:24:19 -0500 |
commit | 70523ba1bbfe206030916c2bc502c0466d064e65 (patch) | |
tree | 11dc2a00e4eefc76bcb307fe575237cd648402f6 /05/main.c | |
parent | f6ee9bfa664430f27fef26e62dfe084c051f58fa (diff) |
if, while, do
Diffstat (limited to '05/main.c')
-rw-r--r-- | 05/main.c | 45 |
1 files changed, 21 insertions, 24 deletions
@@ -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; } |