From: Steven Baltakatei Sandoval Date: Wed, 14 Sep 2022 00:50:00 +0000 (+0000) Subject: feat(src/kr/ch1/s1.7/e1-15):Finish exercise X-Git-Url: https://zdv2.bktei.com/gitweb/BK-2023-05.git/commitdiff_plain/2e0a8c91e0cb2722415c1ab49caa94dfcffc77db feat(src/kr/ch1/s1.7/e1-15):Finish exercise - Note: Fahrenheit to Celsius conversion program utilizing functions. --- 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 0000000..5806ed1 Binary files /dev/null and b/src/kr_exercises/ch1/s1.7/e1-15..c_to_f differ 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|?>>