shithub: c-2nd-ed

Download patch

ref: fa760fc4c5c448f078a428f7638b1a5e6637ade2
author: glenda <glenda@pi>
date: Thu Mar 5 10:50:46 EST 2026

numero uno (first 5 exercises)

--- /dev/null
+++ b/1.1.c
@@ -1,0 +1,11 @@
+// the first c program
+
+#include <u.h>
+#include <libc.h>
+
+void
+main()
+{
+print("hello, world\n");
+exits(nil);
+}
--- /dev/null
+++ b/1.2.c
@@ -1,0 +1,13 @@
+// a modified 'hello world' that employs the '\' method
+// to print the last letter in world
+
+#include <u.h>
+#include <libc.h>
+
+void
+main()
+{
+// 0x7f = del
+print("hello, worl\x64\n");
+exits(nil);
+}
--- /dev/null
+++ b/1.3.c
@@ -1,0 +1,31 @@
+// print a fahrenheit -> celsius table
+// for fahr = 0, 20, ..., 300
+// floating point version
+// modified to include a header above the table
+
+#include <u.h>
+#include <libc.h>
+
+void
+main()
+{
+	float fahr, celsius;
+	int lower, upper, step;
+
+	lower = 0;		// lower limit of table
+	upper = 300;		// upper limit
+	step = 20;		// step size
+
+	fahr = lower;
+
+	print(" F ->  C\n");		// table header
+	print("----------\n");
+
+	while(fahr <= upper){
+		celsius = (5.0 / 9.0) * (fahr - 32.0);
+		print("%3.0f %6.1f\n", fahr, celsius);
+		fahr = fahr + step;
+	}
+
+	exits(nil);
+}
--- /dev/null
+++ b/1.4.c
@@ -1,0 +1,30 @@
+// print the corresponding celsius -> fahrenheit table
+// for celsius = -80, -64, -48, ..., 160
+// floating point version
+
+#include <u.h>
+#include <libc.h>
+
+void
+main()
+{
+	float celsius, fahr;
+	int lower, upper, step;
+
+	lower = -80;		// lower limit of table
+	upper = 160;		// upper limit
+	step = 16;		// step size
+
+	celsius = lower;
+
+	print("  C  ->  F\n");		// table header
+	print("-----------\n");
+
+	while(celsius <= upper){
+		fahr = (celsius * 1.8) + 32;
+		print("%4.0f %6.0f\n", celsius, fahr);
+		celsius = celsius + step;
+	}
+
+	exits(nil);
+}
--- /dev/null
+++ b/1.5.c
@@ -1,0 +1,13 @@
+// a more concise, for-loop generated table
+// modified to run in reverse from 300, 280, 260, ..., 0
+
+#include <u.h>
+#include <libc.h>
+
+void
+main()
+{
+	int fahr;
+	for (fahr = 300; fahr >= 0; fahr -= 20)
+		print("%3d %6.1f\n", fahr, (5.0 / 9.0) * (fahr - 32));
+}
--- /dev/null
+++ b/LICENSE
@@ -1,0 +1,17 @@
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
--- /dev/null
+++ b/README
@@ -1,0 +1,11 @@
+this repo contains my solutions to each chapters' programming exercises found in the book
+'the c programming language' by brian w. kernighan and dennis m. ritchie, the second edition.
+
+emphasis should be placed on the fact that these solutions are mine, and should not be 
+considered to be conclusive, exhaustive, or containing best practices.  i have lots to learn!
+
+included in the root directory is a copy of /lib/legal/mit from 9front as a LICENSE.  when
+necessary i have relied on the source code and excellent manuals and documentation of the
+9front system (/sys/src, /sys/man, and /sys/doc).
+
+this project is a work in progress.
--