C PROGRAMMING ALL FORMULAS
C programming doesn't have specific "formulas" like you might find in mathematics, but it does have various syntax and operators that you use to perform calculations and operations. Here are some fundamental mathematical and logical operators and expressions in C:
1. **Arithmetic Operators:**
- Addition: `+`
- Subtraction: `-`
- Multiplication: `*`
- Division: `/`
- Modulus (remainder): `%`
2. **Assignment Operators:**
- Assignment: `=`
- Compound assignments: `+=`, `-=`, `*=`, `/=`, `%=` (e.g., `x += 5` is equivalent to `x = x + 5`)
3. **Comparison Operators:**
- Equal to: `==`
- Not equal to: `!=`
- Greater than: `>`
- Less than: `<`
- Greater than or equal to: `>=`
- Less than or equal to: `<=`
4. **Logical Operators:**
- Logical AND: `&&`
- Logical OR: `||`
- Logical NOT: `!`
5. **Bitwise Operators:**
- Bitwise AND: `&`
- Bitwise OR: `|`
- Bitwise XOR: `^`
- Bitwise NOT: `~`
- Left shift: `<<`
- Right shift: `>>`
6. **Increment and Decrement Operators:**
- Increment: `++`
- Decrement: `--`
7. **Conditional (Ternary) Operator:**
- It's used for conditional expressions: `condition ? expression_if_true : expression_if_false`
8. **Math Library Functions:**
- C provides a math library (math.h) with functions for more complex mathematical operations, such as `sqrt()`, `sin()`, `cos()`, `exp()`, `log()`, etc.
9. **Precedence Rules:**
- Operator precedence determines the order of evaluation in complex expressions. For example, multiplication and division are evaluated before addition and subtraction.
Here are a few examples of expressions in C:
- Addition: `int sum = 5 + 3;`
- Division: `double result = 10.0 / 3.0;`
- Logical AND: `int result = (x > 5) && (y < 10);`
- Increment: `count++;`
- Square root: `double squareRoot = sqrt(25.0);`
While C doesn't have "formulas" in the same way that mathematics does, you can use these operators and functions to perform a wide range of calculations and operations within your C programs. The choice of which operator or function to use depends on the specific task you want to accomplish.
Comments
Post a Comment