From 442a49ad5a48d417345959b903ae6a6d32d55759 Mon Sep 17 00:00:00 2001 From: Haidong Ji Date: Fri, 15 Apr 2022 15:51:30 -0500 Subject: Great C programming fun Excellent fundamentals and displine training, many tools and techniques exercises: gdb, emacs, valgrind, git --- 21_read_rec1/.gitignore | 2 ++ 21_read_rec1/README | 4 ++++ 21_read_rec1/answer.txt | 4 ++++ 21_read_rec1/grade.txt | 5 +++++ 21_read_rec1/test.c | 28 ++++++++++++++++++++++++++++ 5 files changed, 43 insertions(+) create mode 100644 21_read_rec1/.gitignore create mode 100644 21_read_rec1/README create mode 100644 21_read_rec1/answer.txt create mode 100644 21_read_rec1/grade.txt create mode 100644 21_read_rec1/test.c (limited to '21_read_rec1') diff --git a/21_read_rec1/.gitignore b/21_read_rec1/.gitignore new file mode 100644 index 0000000..08001c7 --- /dev/null +++ b/21_read_rec1/.gitignore @@ -0,0 +1,2 @@ +test +Makefile diff --git a/21_read_rec1/README b/21_read_rec1/README new file mode 100644 index 0000000..bebd9b8 --- /dev/null +++ b/21_read_rec1/README @@ -0,0 +1,4 @@ +Execute the code in test.c (by hand). Write the resulting output in a file +called "answer.txt". + +Check your work, and submit as usual. diff --git a/21_read_rec1/answer.txt b/21_read_rec1/answer.txt new file mode 100644 index 0000000..d83d20b --- /dev/null +++ b/21_read_rec1/answer.txt @@ -0,0 +1,4 @@ +a=29, b=7 +a=2, b=9 +a=0, b=2 +297 diff --git a/21_read_rec1/grade.txt b/21_read_rec1/grade.txt new file mode 100644 index 0000000..27dbba2 --- /dev/null +++ b/21_read_rec1/grade.txt @@ -0,0 +1,5 @@ +Grading at Fri 29 Oct 2021 02:12:30 AM UTC +Your file matched the expected output +Your output matched what we expected + +Overall Grade: A diff --git a/21_read_rec1/test.c b/21_read_rec1/test.c new file mode 100644 index 0000000..52fd4e4 --- /dev/null +++ b/21_read_rec1/test.c @@ -0,0 +1,28 @@ +#include +#include + +void printDigits(int x) { + if (x == 0) { + printf("0"); + } + else if (x < 0) { + printf("-"); + printDigits(-x); + } + else { + int a = x/10; + int b = x %10; + printf("a=%d, b=%d\n",a,b); + if (a != 0) { + printDigits(a); + } + printf("%d",b); + } +} + + +int main(void) { + printDigits(297); + printf("\n"); + return EXIT_SUCCESS; +} -- cgit v1.2.3