Add an example script file which computes prime numbers, and complete
with a C version for execution efficiency comparison.
05.avsl \
"
+# Include example text file to each lesson
+
text=text.txt
for f in $folders; do
done
done
+# Include script examples to lesson 4
+
+cp prime.sh prime.c $file/04.stil
+
+# Compress and cleanup
+
tar -cvf $file.tar $file
rm -fr $file
--- /dev/null
+#!/bin/env bash
+
+# Prints prime numbers, dividable evenly only by itself and one
+
+# Here are alternative methods
+
+N=99
+i=1; printf "%4d" $i
+i=2; printf "%4d" $i
+while [[ $i < $N ]]; do
+ i=$(( $i + 1 ))
+ if ! seq 2 $(( i - 1 )) | sed "s/^/$i%/" | bc | grep -q "^0$"; then
+ printf "%4d" $i
+ fi
+done
+printf "\n"
--- /dev/null
+/* Prints prime numbers, dividable evenly only by itself and one */
+
+#include <stdio.h>
+
+#define N 99
+
+int main(void)
+{
+ int i, j;
+ i = 1;
+ printf ("%5d", i);
+ while (i < N)
+ {
+ i++;
+ j = 2;
+ while (i % j != 0) j++;
+ if (j == i) printf ("%5d", i);
+ }
+ printf ("\n");
+}
--- /dev/null
+#!/bin/env bash
+
+# Prints prime numbers, dividable evenly only by itself and one
+
+N=99
+
+i=1
+printf "%5d" $i
+while [[ $i < $N ]]; do
+ i=$(( $i + 1 ))
+ j=2
+ while [[ $(( $i % $j )) != 0 ]]; do
+ j=$(( $j + 1 ))
+ done
+ if [[ $j = $i ]]; then
+ printf "%5d" $i
+ fi
+done
+printf "\n"