mirror of
https://github.com/kmc7468/cs420.git
synced 2025-12-16 15:38:48 +00:00
Update homework 1 and 2
This commit is contained in:
3205
examples/hw1/complete_cond.c
Normal file
3205
examples/hw1/complete_cond.c
Normal file
File diff suppressed because it is too large
Load Diff
13
examples/hw1/cond_and_loop.c
Normal file
13
examples/hw1/cond_and_loop.c
Normal file
@@ -0,0 +1,13 @@
|
||||
int main() {
|
||||
int i;
|
||||
int p = 2;
|
||||
int q = 5;
|
||||
int r = (0 ? ((p > q) ? (p -= 2) : (p += 2)) : (p + q));
|
||||
|
||||
for (i = 0; i < 11; ((i % 2) ? (i += 2) : ++i)) {
|
||||
if (i % 2) { p += q; }
|
||||
else { p += r; }
|
||||
}
|
||||
|
||||
return p == 34;
|
||||
}
|
||||
15
examples/hw1/gcd.c
Normal file
15
examples/hw1/gcd.c
Normal file
@@ -0,0 +1,15 @@
|
||||
int gcd(int a, int b) {
|
||||
a = (a > 0) ? a : -a;
|
||||
b = (b > 0) ? b : -b;
|
||||
|
||||
while(a != b) {
|
||||
if(a > b) { a -= b; }
|
||||
else { b -= a; }
|
||||
}
|
||||
|
||||
return a;
|
||||
}
|
||||
|
||||
int main() {
|
||||
return gcd(18, 21) == 3;
|
||||
}
|
||||
Reference in New Issue
Block a user