Mattingly "AI & Prompt Design: The Basics of Prompt Design"
test(3)arithmetic in c
1. Arithmetic In C
Computer Science: A Structured Programming Approach Using C 1
2. Arithmetic In C
To solve most programming problems, you need to write
arithmetic operations that manipulate type integer, float and
double data.
C enables programmers to perform all types of arithmetic
calculations. Most common used arithmetic operators are:
Computer Science: A Structured Programming Approach Using C 2
4. Expression
•An expression is a sequence of operands and
operators that reduces to a single value.
Expressions can be simple or complex.
•An operator is a syntactical token that requires an
action be taken.
•An operand is an object on which an operation is
performed; it receives an operator’s action.
Computer Science: A Structured Programming Approach Using C 4
5. Expression
Result = Operand1 + Operand2
The equal sign (=) is an assignment operator where
the right side is being assigned to the left side of the
operator (=) .
Computer Science: A Structured Programming Approach Using C 5
6. Both operands of the modulus operator (%) must
be integer types.
Note
Computer Science: A Structured Programming Approach Using C 6
10. Converting Algebra Formulas
To C Formulas
•Always specify multiplication with the symbol *.
•C explicitly require the multiplication operator.
Example: a*b ( cannot put it as ab )
•Use parentheses when required to control the
order of operator evaluation.
Computer Science: A Structured Programming Approach Using C 10
12. Precedence and Associativity
•Precedence is used to determine the order in which
different operators in a complex expression are
evaluated.
•Associativity is used to determine the order in which
operators with the same precedence are evaluated in a
complex expression.
Left-to-Right Associativity
Computer Science: A Structured Programming Approach Using C 12
18. Compound Expression
Compound
Expression
Equivalent Simple
Expression
X*=3 X=X*3
X/=3 X=X/3
X%=3 X=X%3
X+=1 X=X+1
X-=1 X=X-1
Computer Science: A Structured Programming Approach Using C 18
19. Increment and Decrement Operator
Increment Decrement
Prefix Increment Postfix Increment Prefix Decrement Postfix Decrement
++a a++ --a a--
Increment a by 1
then use the new
value of a in the
expression.
Use the current
value of a in the
expression, then
increment a by 1.
Decrement a by 1
then use the new
value of a in the
expression.
Use the current
value of a in the
expression, then
decrement a by 1.
Computer Science: A Structured Programming Approach Using C 19