Professional Documents
Culture Documents
Aritmetic Operations
"Good things come to people who wait, but better things come
to those who go out and get them."
--Anonymous
Internal
Arithmetic Operations
• Assignment operator
• Arithmetic operators
• Increment/decrement operators
• scanf() input function
• Order of arithmetic operations
Internal
Assignment Operator
• Basic format:
variable = expression;
“assignment statement”
• Examples:
x = 1;
abc = 123.45;
half = number/2;
Internal
Assignment Operator (2)
expression
variable
Internal
Arithmetic Operators
Operator Operation
+ Addition
- Subtraction
* Multiplication
/ Division
% Remainder of division
Internal
Arithmetic Operators (2)
Internal
Remainder Operator (%)
• Increment (++)
– Post-increment: x++ ….. x = x + 1
– Pre-increment: ++x ..... x = x + 1
• Decrement (--)
– Post-decrement: x-- ….. x = x + 1
– Pre-increment: --x ..... x = x - 1
Internal
Increment and Decrement Operators (2)
Internal
Increment and Decrement Operators (3)
Post-increment:
• x++; ..... x = x + 1;
• y = x++; ..... y = x; x = x + 1;
Pre-increment:
• ++x; ..... x = x + 1;
• y = ++x; ..... x = x + 1; y = x;
Internal
Input Function scanf() (2)
Basic format:
scanf("format specifiers", variables);
Examples:
• scanf("%d", &x); // Read a decimal integer into variable x
• scanf("%i", &x); // Read a decimal integer into variable x
Internal
Input Function scanf() (3)
/* Program 2.6 - This program reads two numbers from the keyboard
and displays the sum on the monitor screen
*/
#include <stdio.h>
int main(void)
{
int first, second, sum;
return 0;
Internal }
Order of Operations - BODMAS
"Operations" mean things like add, subtract, multiply, divide, squaring, etc.
If it isn't a number it is probably an operation.
B Brackets first
Internal
http://www.mathsisfun.com/operation-order-bodmas.html
An Example
7 + (6 × 52 + 3)
Start inside Brackets, and then use
7 + (6 × 25 + 3)
"Orders" First
7 + (150 + 3) Then Multiply
Internal
"A C program is like a fast dance on a newly waxed dance
floor by people carrying razors.“
Internal