summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormartin@ashbysoft.com <martin@ashbysoft.com>2022-06-11 20:02:48 +0000
committermartin@ashbysoft.com <martin@ashbysoft.com>2022-06-11 20:02:48 +0000
commitc813f7bd522baf1057ba9bee874669ea5b945a66 (patch)
treedfb3c1dc231ad779cd693d3890bd154839ea5121
parent9688990db4ce2078a0027315ca80b5717fc5cacd (diff)
downloadlearn-c-c813f7bd522baf1057ba9bee874669ea5b945a66.tar.gz
learn-c-c813f7bd522baf1057ba9bee874669ea5b945a66.tar.bz2
learn-c-c813f7bd522baf1057ba9bee874669ea5b945a66.tar.xz
learn-c-c813f7bd522baf1057ba9bee874669ea5b945a66.zip
more intro exercises
-rw-r--r--echo.c9
-rw-r--r--ex1-6.c7
-rw-r--r--ex1-7.c5
-rw-r--r--fahr-celc.c6
-rwxr-xr-xrun7
5 files changed, 31 insertions, 3 deletions
diff --git a/echo.c b/echo.c
new file mode 100644
index 0000000..bf590a5
--- /dev/null
+++ b/echo.c
@@ -0,0 +1,9 @@
+#include <stdio.h>
+
+int main(void) {
+ int c;
+ while ((c = getchar()) != EOF) {
+ putchar(c);
+ }
+ return 0;
+} \ No newline at end of file
diff --git a/ex1-6.c b/ex1-6.c
new file mode 100644
index 0000000..73e9010
--- /dev/null
+++ b/ex1-6.c
@@ -0,0 +1,7 @@
+#include <stdio.h>
+int main(void) {
+ while (1) {
+ printf("%d\n", getchar()==EOF);
+ }
+ return 0;
+} \ No newline at end of file
diff --git a/ex1-7.c b/ex1-7.c
new file mode 100644
index 0000000..e84b0af
--- /dev/null
+++ b/ex1-7.c
@@ -0,0 +1,5 @@
+#include <stdio.h>
+int main(void) {
+ printf("%d\n", EOF);
+ return 0;
+} \ No newline at end of file
diff --git a/fahr-celc.c b/fahr-celc.c
index ccef413..ac3c2fc 100644
--- a/fahr-celc.c
+++ b/fahr-celc.c
@@ -3,9 +3,9 @@
/* print farenheight-celcius
conversion table for 0, 20, ...300 */
int main() {
- for (float fahr=0.0;
- fahr<=300.0;
- fahr+=20.0) {
+ for (float fahr=300.0;
+ fahr>=0.0;
+ fahr-=20.0) {
printf("%3.0f %6.1f\n",
fahr,
(5.0/9.0)*(fahr-32.0));
diff --git a/run b/run
new file mode 100755
index 0000000..185f869
--- /dev/null
+++ b/run
@@ -0,0 +1,7 @@
+#!/usr/bin/env bash
+set -e
+cc -o exe $@
+./exe
+result=$?
+rm exe
+exit $result \ No newline at end of file