diff options
Diffstat (limited to 'examples')
-rw-r--r-- | examples/gcd.c | 12 | ||||
-rw-r--r-- | examples/gcd_nd.c | 15 | ||||
-rw-r--r-- | examples/loop.c | 3 | ||||
-rw-r--r-- | examples/loop2.c | 2 | ||||
-rw-r--r-- | examples/loop3.c | 3 | ||||
-rw-r--r-- | examples/loop4.c | 2 |
6 files changed, 37 insertions, 0 deletions
diff --git a/examples/gcd.c b/examples/gcd.c new file mode 100644 index 0000000..1f66332 --- /dev/null +++ b/examples/gcd.c @@ -0,0 +1,12 @@ +a = -26134272; +b = 26396928; + +if (a < 0) a = -a; +if (b < 0) b = -b; +while (b > 0) { // try changing this to b >= 0 + tmp = b; + b = a % b; + a = tmp; + } +print (a); // this should print 131328 + diff --git a/examples/gcd_nd.c b/examples/gcd_nd.c new file mode 100644 index 0000000..260af41 --- /dev/null +++ b/examples/gcd_nd.c @@ -0,0 +1,15 @@ +a = rand(5,15); +b = rand(3,8); + +if (a < 0) a = -a; +if (b < 0) b = -b; +while (b > 0) { // try changing this to b >= 0 + tmp = b; + b = a % b; + a = tmp; + } +assert (b==0); // should be true +//assert (a>6); // try uncommenting this line +tmp = 0; +print (a); + diff --git a/examples/loop.c b/examples/loop.c new file mode 100644 index 0000000..7e22dfa --- /dev/null +++ b/examples/loop.c @@ -0,0 +1,3 @@ +x = 0; +while (x >= 0) { } + diff --git a/examples/loop2.c b/examples/loop2.c new file mode 100644 index 0000000..64f05c9 --- /dev/null +++ b/examples/loop2.c @@ -0,0 +1,2 @@ +x = 0; +while (x <= 0) x = x-1; diff --git a/examples/loop3.c b/examples/loop3.c new file mode 100644 index 0000000..f22958c --- /dev/null +++ b/examples/loop3.c @@ -0,0 +1,3 @@ +x = 5; +while (x < 10) { x=x-1; y=1/x; } + diff --git a/examples/loop4.c b/examples/loop4.c new file mode 100644 index 0000000..6cbe12c --- /dev/null +++ b/examples/loop4.c @@ -0,0 +1,2 @@ +x = rand(-10,10); +while (x <= 0) x = x-1; |