summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--cbook/one_one.c34
-rw-r--r--cbook/one_two.c36
3 files changed, 71 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index dac5b51..a501e69 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,3 @@
clip/clip
parsing/parsing
+a.out
diff --git a/cbook/one_one.c b/cbook/one_one.c
new file mode 100644
index 0000000..9896026
--- /dev/null
+++ b/cbook/one_one.c
@@ -0,0 +1,34 @@
+#include <stdio.h>
+
+/*
+* Tell the compiler that we intend
+* to use a function called show_message.
+* It has no arguments and returns no value
+* This is the "declaration".
+*
+*/
+
+void show_message(void);
+/*
+* Another function, but this includes the body of
+* the function. This is a "definition".
+*/
+int main(){
+ int count;
+
+ count = 0;
+ while(count < 10){
+ show_message();
+ count = count + 1;
+ }
+
+ return(0);
+}
+
+/*
+* The body of the simple function.
+* This is now a "definition".
+*/
+void show_message(void){
+ printf("hello\n");
+}
diff --git a/cbook/one_two.c b/cbook/one_two.c
new file mode 100644
index 0000000..a5bf221
--- /dev/null
+++ b/cbook/one_two.c
@@ -0,0 +1,36 @@
+/*
+*
+* Dumb program that generates prime numbers.
+*/
+#include <stdio.h>
+#include <stdlib.h>
+
+
+int is_prime(int x) {
+ for (int i=2; i<x; i++) {
+ if (x % i == 0 && i != x) return 0;
+ }
+ return 1;
+}
+
+
+
+
+int main(){
+ int this_number, prime, next_prime, next_number;
+
+ this_number = 3;
+
+ while(this_number < 10000){
+ prime = is_prime(this_number);
+ if (prime == 1) {
+ next_number = this_number + 2;
+ next_prime = is_prime(next_number);
+ if (next_prime == 1)
+ printf("%d and %d are prime pair\n", this_number, next_number);
+ }
+ this_number++;
+
+ }
+ exit(EXIT_SUCCESS);
+}