mirror of
https://github.com/kmc7468/cs420.git
synced 2025-12-14 22:38:46 +00:00
Initial commit
This commit is contained in:
3
examples/alignof.c
Normal file
3
examples/alignof.c
Normal file
@@ -0,0 +1,3 @@
|
||||
int main() {
|
||||
return _Alignof(const int);
|
||||
}
|
||||
6
examples/bar.c
Normal file
6
examples/bar.c
Normal file
@@ -0,0 +1,6 @@
|
||||
int bar(int x, int y, int z){
|
||||
int arith_mean = (x + y + z) / 3;
|
||||
int ugly_mean = (((x + y) / 2) * 2 + z) / 3;
|
||||
if (x == y) { return y; }
|
||||
else { return z; }
|
||||
}
|
||||
6
examples/comma.c
Normal file
6
examples/comma.c
Normal file
@@ -0,0 +1,6 @@
|
||||
int main()
|
||||
{
|
||||
int y = 2;
|
||||
int x = (y += 2, 2, y + 3);
|
||||
return x;
|
||||
}
|
||||
6
examples/cond.c
Normal file
6
examples/cond.c
Normal file
@@ -0,0 +1,6 @@
|
||||
int main()
|
||||
{
|
||||
int y = 1;
|
||||
int x = 0;
|
||||
return (x == y) ? 2 : 5;
|
||||
}
|
||||
7
examples/fib2.c
Normal file
7
examples/fib2.c
Normal file
@@ -0,0 +1,7 @@
|
||||
int (fibonacci)(int n) {
|
||||
if (n < 2) {
|
||||
return n;
|
||||
}
|
||||
|
||||
return fibonacci(n - 2) + fibonacci(n - 1);
|
||||
}
|
||||
20
examples/fib3.c
Normal file
20
examples/fib3.c
Normal file
@@ -0,0 +1,20 @@
|
||||
int fibonacci(int n) {
|
||||
int i = 0;
|
||||
int t1 = 0, t2 = 1, next_term = 0;
|
||||
|
||||
if (n < 2) {
|
||||
return n;
|
||||
}
|
||||
|
||||
for (i = 1; i < n; ++i) {
|
||||
next_term = t1 + t2;
|
||||
t1 = t2;
|
||||
t2 = next_term;
|
||||
}
|
||||
|
||||
return t2;
|
||||
}
|
||||
|
||||
int main() {
|
||||
return fibonacci(9);
|
||||
}
|
||||
22
examples/fib4.c
Normal file
22
examples/fib4.c
Normal file
@@ -0,0 +1,22 @@
|
||||
int fibonacci(int n) {
|
||||
int i = 0;
|
||||
int t1 = 0, t2 = 1, next_term = 0;
|
||||
|
||||
if (n < 2) {
|
||||
return n;
|
||||
}
|
||||
|
||||
i = 1;
|
||||
while (i < n) {
|
||||
next_term = t1 + t2;
|
||||
t1 = t2;
|
||||
t2 = next_term;
|
||||
++i;
|
||||
}
|
||||
|
||||
return t2;
|
||||
}
|
||||
|
||||
int main() {
|
||||
return fibonacci(9);
|
||||
}
|
||||
22
examples/fib5.c
Normal file
22
examples/fib5.c
Normal file
@@ -0,0 +1,22 @@
|
||||
int fibonacci(int n) {
|
||||
int i = 0;
|
||||
int t1 = 0, t2 = 1, next_term = 0;
|
||||
|
||||
if (n < 2) {
|
||||
return n;
|
||||
}
|
||||
|
||||
i = 1;
|
||||
do {
|
||||
next_term = t1 + t2;
|
||||
t1 = t2;
|
||||
t2 = next_term;
|
||||
++i;
|
||||
} while (i < n);
|
||||
|
||||
return t2;
|
||||
}
|
||||
|
||||
int main() {
|
||||
return fibonacci(9);
|
||||
}
|
||||
11
examples/fibonacci.c
Normal file
11
examples/fibonacci.c
Normal file
@@ -0,0 +1,11 @@
|
||||
int fibonacci(int n) {
|
||||
if (n < 2) {
|
||||
return n;
|
||||
}
|
||||
|
||||
return fibonacci(n - 2) + fibonacci(n - 1);
|
||||
}
|
||||
|
||||
int main() {
|
||||
return fibonacci(9);
|
||||
}
|
||||
8
examples/foo.c
Normal file
8
examples/foo.c
Normal file
@@ -0,0 +1,8 @@
|
||||
int foo(int x, int y, int z){
|
||||
if (x == y) { return y; }
|
||||
else { return z; }
|
||||
}
|
||||
|
||||
int main() {
|
||||
return foo(0, 1, -1);
|
||||
}
|
||||
9
examples/foo2.c
Normal file
9
examples/foo2.c
Normal file
@@ -0,0 +1,9 @@
|
||||
int main() {
|
||||
int i = 0;
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
int i = 0;
|
||||
int k = 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
13
examples/foo3.c
Normal file
13
examples/foo3.c
Normal file
@@ -0,0 +1,13 @@
|
||||
int g = 10;
|
||||
|
||||
int foo(int, int k);
|
||||
|
||||
int main() {
|
||||
int i = g;
|
||||
|
||||
return foo(i, i);
|
||||
}
|
||||
|
||||
int foo(int i, int j) {
|
||||
return i + j + g;
|
||||
}
|
||||
15
examples/foo4.c
Normal file
15
examples/foo4.c
Normal file
@@ -0,0 +1,15 @@
|
||||
int foo(int i, int j, int k) {
|
||||
return i + j + k;
|
||||
}
|
||||
|
||||
int (* foo2())(int, int, int){
|
||||
return foo;
|
||||
}
|
||||
|
||||
int (* (* foo3())())(int, int, int){
|
||||
return foo2;
|
||||
}
|
||||
|
||||
int main() {
|
||||
return foo3()()(2, 2, 2);
|
||||
}
|
||||
8
examples/negate.c
Normal file
8
examples/negate.c
Normal file
@@ -0,0 +1,8 @@
|
||||
int foo(int x, int y, int z){
|
||||
if (!(x == y)) { return y; }
|
||||
else { return z; }
|
||||
}
|
||||
|
||||
int main() {
|
||||
return foo(0, 1, -1);
|
||||
}
|
||||
15
examples/pointer.c
Normal file
15
examples/pointer.c
Normal file
@@ -0,0 +1,15 @@
|
||||
int* foo(int *a){
|
||||
return a;
|
||||
}
|
||||
|
||||
int main(){
|
||||
int a = 1;
|
||||
int *p = &a;
|
||||
int **p2 = &*&p;
|
||||
int *p3 = *&p;
|
||||
|
||||
*&*foo(*p2) += 1;
|
||||
*foo(p3) += 1;
|
||||
|
||||
return a;
|
||||
}
|
||||
7
examples/return_void.c
Normal file
7
examples/return_void.c
Normal file
@@ -0,0 +1,7 @@
|
||||
void foo() {
|
||||
}
|
||||
|
||||
int main() {
|
||||
foo();
|
||||
return 0;
|
||||
}
|
||||
4
examples/simple.c
Normal file
4
examples/simple.c
Normal file
@@ -0,0 +1,4 @@
|
||||
int main()
|
||||
{
|
||||
int x = 1;
|
||||
}
|
||||
9
examples/simple_for.c
Normal file
9
examples/simple_for.c
Normal file
@@ -0,0 +1,9 @@
|
||||
int main()
|
||||
{
|
||||
int i;
|
||||
int sum = 0;
|
||||
for (i = 0; i < 11; ++i) {
|
||||
sum += i;
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
7
examples/simple_if.c
Normal file
7
examples/simple_if.c
Normal file
@@ -0,0 +1,7 @@
|
||||
int (fibonacci)(int n) {
|
||||
if (n < 2) {
|
||||
n += 2;
|
||||
}
|
||||
|
||||
return fibonacci(n - 2) + fibonacci(n - 1);
|
||||
}
|
||||
3
examples/sizeof.c
Normal file
3
examples/sizeof.c
Normal file
@@ -0,0 +1,3 @@
|
||||
int main() {
|
||||
return sizeof(const int);
|
||||
}
|
||||
20
examples/switch.c
Normal file
20
examples/switch.c
Normal file
@@ -0,0 +1,20 @@
|
||||
int main() {
|
||||
int a = 1;
|
||||
int b = 0;
|
||||
switch (a) {
|
||||
case 0: {
|
||||
b += 1;
|
||||
break;
|
||||
}
|
||||
case 1: {
|
||||
b += 2;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
b += 3;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return b;
|
||||
}
|
||||
5
examples/temp.c
Normal file
5
examples/temp.c
Normal file
@@ -0,0 +1,5 @@
|
||||
int fibonacci(int n) {
|
||||
while (n + n) {
|
||||
return n;
|
||||
}
|
||||
}
|
||||
26
examples/temp2.c
Normal file
26
examples/temp2.c
Normal file
@@ -0,0 +1,26 @@
|
||||
int f(int i, int const a[const i]) {
|
||||
int temp = 0;
|
||||
const float temp2 = 0.f, temp3 = 0.f;
|
||||
temp = sizeof(unsigned char);
|
||||
temp = _Alignof(unsigned char);
|
||||
|
||||
struct color { int number; char name; } c;
|
||||
c.name;
|
||||
struct color *cp = &c;
|
||||
cp->name;
|
||||
|
||||
for(int i = 0, j = 0; i < 10; ++i) {
|
||||
break;
|
||||
}
|
||||
|
||||
switch(temp) {
|
||||
case 1: {
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return temp;
|
||||
}
|
||||
Reference in New Issue
Block a user