From 2e0a8c91e0cb2722415c1ab49caa94dfcffc77db Mon Sep 17 00:00:00 2001 From: Steven Baltakatei Sandoval Date: Wed, 14 Sep 2022 00:50:00 +0000 Subject: [PATCH] feat(src/kr/ch1/s1.7/e1-15):Finish exercise - Note: Fahrenheit to Celsius conversion program utilizing functions. --- src/kr_exercises/ch1/s1.2/s1.2..f_to_c.c | 19 +++++++ src/kr_exercises/ch1/s1.7/e1-15..c_to_f | Bin 0 -> 15992 bytes src/kr_exercises/ch1/s1.7/e1-15..c_to_f.c | 33 ++++++++++++ src/notes.tm | 63 ++++++++++++++-------- 4 files changed, 94 insertions(+), 21 deletions(-) create mode 100644 src/kr_exercises/ch1/s1.2/s1.2..f_to_c.c create mode 100755 src/kr_exercises/ch1/s1.7/e1-15..c_to_f create mode 100644 src/kr_exercises/ch1/s1.7/e1-15..c_to_f.c diff --git a/src/kr_exercises/ch1/s1.2/s1.2..f_to_c.c b/src/kr_exercises/ch1/s1.2/s1.2..f_to_c.c new file mode 100644 index 0000000..e2ff1cf --- /dev/null +++ b/src/kr_exercises/ch1/s1.2/s1.2..f_to_c.c @@ -0,0 +1,19 @@ +#include + +/* print Fahrenheit-Celsius table for fahr = 0, 20, ..., 300 */ + +int main() { + int fahr, celsius; + int lower, upper, step; + + lower = 0; /* lower limit of temperature table */ + upper = 300; /* upper limit */ + step = 20; /* step size */ + + fahr = lower; + while (fahr <= upper) { + celsius = 5 * (fahr-32) / 9; + printf("%d\t%d\n", fahr, celsius); + fahr = fahr + step; + } +} diff --git a/src/kr_exercises/ch1/s1.7/e1-15..c_to_f b/src/kr_exercises/ch1/s1.7/e1-15..c_to_f new file mode 100755 index 0000000000000000000000000000000000000000..5806ed18cc9d589a37beb014842ad0b1e1cc173f GIT binary patch literal 15992 zcmeHOYit}>6~4Q9In;?aX+raWc!8#B08i}1F-}_($M!noDi4!5KqZpN+B>#a+K0P4 z+u9WrL!j!)4GmHS2>PQ)pdtZMkU$vm16wI^!lQEd6@)i06PVV$5?M?)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`?LYdm^cM^Ds&M3Fexx@imlFF0uKO8>IHm2=OMwWyYMc6T+W|-uPg^AWB2M$(SsDqjCAChI#*oPK+E1r N`e%2zQ5$Zf|2NlqBANgI literal 0 HcmV?d00001 diff --git a/src/kr_exercises/ch1/s1.7/e1-15..c_to_f.c b/src/kr_exercises/ch1/s1.7/e1-15..c_to_f.c new file mode 100644 index 0000000..1210d38 --- /dev/null +++ b/src/kr_exercises/ch1/s1.7/e1-15..c_to_f.c @@ -0,0 +1,33 @@ +#include + +int f_to_c(int degf); + +/* print Fahrenheit-Celsius table for fahr = 0, 20, ..., 300 */ + +int main() { + int fahr, celsius; + int lower, upper, step; + + lower = 0; /* lower limit of temperature table */ + upper = 300; /* upper limit */ + step = 20; /* step size */ + + fahr = lower; + while (fahr <= upper) { + celsius = f_to_c(fahr); + /* celsius = 5 * (fahr-32) / 9; */ + printf("%d\t%d\n", fahr, celsius); + fahr = fahr + step; + }; +}; + +/* f_to_c: calculate celsius from fahrenheit */ +int f_to_c(int degf) { + int degc; + degc = 5 * (degf - 32) / 9; + return degc; +}; + +/* Author: Steven Baltakatei Sandoval + License: GPLv3+ +*/ diff --git a/src/notes.tm b/src/notes.tm index ebe2879..37db349 100644 --- a/src/notes.tm +++ b/src/notes.tm @@ -55,10 +55,10 @@ a = ( b = ( c = 0 ) ); - The act of running (or \Pinvoking\Q) a . See - . + The act of running (or \Pinvoking\Q) a + . See . - >A construct that establishes + A construct that establishes an association between a particular variable, function, or type and its attributes<\footnote> See . @@ -68,16 +68,16 @@ with a variable (e.g. ). Compare with . - >A construct that establishes the + A construct that establishes the same associations as a declaration but also causes storage to be allocated for the variable<\footnote> See . . - A source code analysis program - designed to detect common syntactic errors. + A source code analysis program designed + to detect common syntactic errors. - > + (or ) is a user defined data type in . It is mainly used to assign names to integral constants. For example, the declaration =Dec; i++)> to cycle through the integers , 10, 11>. - >A set of characters + A set of characters used to represent hard-to-type or invisible characters. Some commonly used escape sequences in include: @@ -215,8 +215,22 @@ } > - An expression containing the name - followed by the function call operator \P\Q. + An expression containing + the name followed by the function call operator + \P\Q. + + A declaration of + a consisting only of the function name (a.k.a. + \Pidentifier\Q) and parenthesized types so the + compiler knows how to perform -based conversions of + (e.g. truncating a into an ) in + of the function before the compiler knows the function + <\footnote> + See . + . The function prototype parameter names do not have to agree + with the function definition parameter names<\footnote> + K&R 2nd Ed., Sec 1.7 \PFunctions\Q. + . The process of freeing memory allocated by a program but which is no longer referenced. @@ -288,10 +302,10 @@ followed by a newline character. (See K&R 2nd Ed. Section 1.5 \PCharacter Input and Output\Q) - A way of differentiating data stored for use in a program. - Some types include (integers), (single-byte - characters), (a short integer), (a long integer), - (a double-precision floating point number). + A way of differentiating data stored for use + in a program. Some types include (integers), + (single-byte characters), (a short integer), (a + long integer), (a double-precision floating point number). \; @@ -396,6 +410,7 @@ > > > + > > > > @@ -403,12 +418,14 @@ > > > + > > > > > > > + > > > > @@ -416,6 +433,7 @@ > > > + > > > > @@ -426,26 +444,29 @@ > > > - > - |?>> - > + > + > + > > heap|?>> machine-independent|?>> operand|?>> > - > + > struct|?>> > > - > + > + > |prog-language||font-family||\\x>|hh>|?>> > + > + > + > operator|?>> stack|?>> - text stream|?>> + text stream|?>> -- 2.39.5