about summary refs log tree commit diff stats
path: root/tests32/test05.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests32/test05.c')
-rwxr-xr-xtests32/test05.c62
1 files changed, 62 insertions, 0 deletions
diff --git a/tests32/test05.c b/tests32/test05.c
new file mode 100755
index 00000000..c6a4e67f
--- /dev/null
+++ b/tests32/test05.c
@@ -0,0 +1,62 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdint.h>
+
+int fact(int i) {
+    if (i<2) return i;
+    return i*fact(i-1);
+}
+
+#define SET(M) dels[M/8] |= (1<<(M%8))
+#define GET(M) ((dels[M/8]>>(M%8))&1)
+
+int main(int argc, const char** argv)
+{
+    int j = 5;
+    if(argc>1)
+        j = atoi(argv[1]);
+    if(j==0)
+        j=5;
+    if(j>15) j=15;
+    
+    int k = fact(j);
+    printf("fact(%d)=%d\n", j, k);
+
+    uint8_t* dels = (char*)calloc((k+7)/8, 1);
+    SET(0);
+    SET(1);
+ 
+    for (int i=2; i<k; i++)
+        if (!GET(i)) {
+            int m = 2 * i;
+            while (m < k) {
+                SET(m);
+                m += i;
+            }
+        }
+ 
+    printf("Prime list 0..%d: ", k);
+    for (int i=0; i<k; i++)
+        if (!GET(i))
+            printf("%d ", i);
+    printf("\n");
+
+    free(dels);
+
+    signed char sc = -5;
+    unsigned char uc = 83;
+    signed short int ss = -53;
+    unsigned short int us = 65500;
+
+    int it = sc+uc+ss+us;
+
+    printf("(un)signed char = %hhd/%hhu (un)signed int = %hd/%hu total=%d\n", sc, uc, ss, us, it);
+
+    printf("%hu/5=%hu, %hu%%5=%hu\n", us, us/5, us, us%5);
+    printf("%d/5=%d, %d%%5=%d\n", it, it/5, it, it%5);
+
+    printf("%d/%hd=%d + %d", it, ss, it/ss, it%ss);
+
+    return 0;
+}
\ No newline at end of file