From: Steven Baltakatei Sandoval Date: Tue, 13 Sep 2022 11:30:01 +0000 (+0000) Subject: feat(src/kr/ch1/s1.7):Add power function example X-Git-Url: https://zdv2.bktei.com/gitweb/BK-2023-05.git/commitdiff_plain/7736db75bffcdf540e2dbb6d24673d2c02a6c07b feat(src/kr/ch1/s1.7):Add power function example - feat(src/notes.tm):Add more definitions from reading. --- diff --git a/src/kr_exercises/ch1/s1.7/s1.7-1..power.c b/src/kr_exercises/ch1/s1.7/s1.7-1..power.c new file mode 100644 index 0000000..af96ebe --- /dev/null +++ b/src/kr_exercises/ch1/s1.7/s1.7-1..power.c @@ -0,0 +1,22 @@ +#include + +int power(int m, int n); + +/* test power function */ +int main() { + int i; + + for (i = 0; i < 10; ++i) + printf("%d %d %d\n", i, power(2,i), power(-3,i)); + return 0; +}; + +/* power: raise base to n-th power; n >= 0 */ +int power(int base, int n) { + int i, p; + + p = 1; + for (i = 1; i <= n; ++i) + p = p * base; + return p; +}; diff --git a/src/notes.tm b/src/notes.tm index 03d208a..ebe2879 100644 --- a/src/notes.tm +++ b/src/notes.tm @@ -16,6 +16,11 @@ <\description-compact> + >A value used to supply a + in the call of a . Also known as an + \Pactual argument\Q as opposed to \Pformal argument\Q (i.e. + ). See also . + An expression in which a variable is set to a value. For example, in the expression >, the variable is set to the value because is to the left of the equals @@ -50,15 +55,24 @@ a = ( b = ( c = 0 ) ); + The act of running (or \Pinvoking\Q) a . See + . + >A construct that establishes an association between a particular variable, function, or type and its - attributes. (See - and ). - Compare with . - - >A construct that stablishes the + attributes<\footnote> + See . + . Announces the properties of variables. May be a statement + consisting of a name followed by a list of + (e.g. ) or followed by an expression + with a variable (e.g. ). Compare with + . + + >A construct that establishes the same associations as a declaration but also causes storage to be - allocated for the variable. (See ). + allocated for the variable<\footnote> + See . + . A source code analysis program designed to detect common syntactic errors. @@ -116,6 +130,94 @@ includehelp-oct-hex>>). + A sequence of + and that specify a computation. When + evaluated, an expression may perform useful side effects (e.g. + sends the character to \ the standard + output stream)<\footnote> + See . + . + + Arrangements of expressions may include<\footnote> + See . + : + + <\description> + A value with no operator is used<\footnote> + See . + . (e.g. the \P\Q in ) + + A variable evaluated earlier. (e.g. the 2nd + \P\Q in >) + + Operator is used between operands. (e.g. ) + + Operator is used after the operands. (e.g. + ) + + Operator is used before the operands. (e.g. + ) + + There is one operator and one operand. (e.g. + ) + + There is one operator and two operands. (e.g. + ) + + + Types of expressions may include: + + <\description> + Consists of arithmetic operators () and computes values of type. + + Usually uses comparison operators + (, \, \=, \=, ===, and !==>) and + computers answer in the type (i.e. true \P\Q or false + \P\Q). + + Consists of logical operators () and combines relational expressions to compute answers in the + type. + + Consists of statements that return + if the condition is met or otherwise. + + May consist of an ampersand () + operator and returns values. + + Consists of bitwise operators + (\, \\, ~, &, \|, and ^>) and performs + operations at the bit level. + + Involves only constants such that the + expression may be evaluated during compilation rather than + run-time<\footnote> + K&R 2nd Ed., Sec. 2.3 \PConstants\Q. + . + + + A group of statements that perform a + task. Is defined using a function that has a + parenthesized list of called + (e.g. variables for accepting values named as input + when the is called). A function definition has the + form: + + + return-typefunction-name(parameter declarations, if any) { + + declarations + + statements + + } + > + + An expression containing the name + followed by the function call operator \P\Q. + The process of freeing memory allocated by a program but which is no longer referenced. Usually incurs a significant character in , the in , or the in .). + Generally, a variable named in the + parenthesized list in a definition. Also known as a + \Pformal argument\Q as opposed to an \Pactual argument\Q (e.g. + ). See . + stack>A region of memory for global variable storage and is permanent for the entire run of the program. Stack size is limited not by physical memory availability but by the CPU. Lifetime of @@ -156,6 +263,13 @@ memory allocated by declarations within the function is automatically freed. (See ) + An when it is + followed by a semicolon. May be grouped together using braces (i.e. + \P\Q) to form a or which is + syntactically equivalent to a single .<\footnote> + K&R 2nd Ed., Sec. 3.1 \PStatements and Blocks\Q. + + struct>(short: ) a @@ -173,6 +287,11 @@ divided into lines; each line consists of zero or more characters 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). \; @@ -214,6 +333,8 @@ Character codes include: <\description-aligned> + >Used to display a character by its . + >Used with (i.e. 16-bit integers; max value of =32\767>). @@ -227,6 +348,16 @@ >Used with and (double precision ). + + For printing strings (which are multibyte in contrast to + one-byte strings), functions from the C standard library + header file<\footnote> + See . + may need to be<\footnote> + See . + used<\footnote> + See . + (e.g. (?)). \; @@ -265,30 +396,56 @@ > > > + > + > + > + > + > + > + > > > + > + > + > > + > + > + > + > + > + > + > > > + > + > + > > > - > - > - |?>> + > + > + > > |?>> - |prog-language||font-family||\\x>|hh>|?>> + > > heap|?>> machine-independent|?>> operand|?>> - operator|?>> - stack|?>> + > + > struct|?>> > + > > + |prog-language||font-family||\\x>|hh>|?>> + > + operator|?>> + stack|?>> + text stream|?>> @@ -308,6 +465,16 @@ |1.2.1Character Input and Output |.>>>>|> > + + |math-font-series||2Utilities> + |.>>>>|> + + + 2.1Text Editor |.>>>>|> + + + 2.2Linter |.>>>>|> + \ No newline at end of file