Jul 01
- Parenthesis are at the highest level of precedence. In case of nested parenthesis,the innermost parenthesis are evaluated first.
Example
(((3+4)*5)/6)
3+ 4 step 1
7 * 5 step 2
35 / 6 step 3
- Multiplication, division & modulus are evaluated next. If an expression contains several multiplication,division and modulud operators,evaluation precedes from left to right, These three are at same level of precedence.
Example
5 * 5 + 6 *7
5 * 5 step 1
6 * 7 step 2
25 + 42 step 3
Example:
7*2/2%4
7 *2 step 1
14/2 step 2
7%4 step 3
- Addition,subtraction are evaluated last.
Example:
z = 3+ 8 * 7 /4 % 2 – 1
order : * / % + - =
therefore it is evaluated as
- 3+ 8 * 7 /4 % 2 -1
- 3 + 56/4 % 2 -1
- 3 + 14 % 2 – 1
- 3 + 0 -1
- 3-1
- z = 2.
written by Shweta
\\ tags: Airthmetic
Jun 25
- The ‘%‘ (modulus) operator returns the remainder on dividing one integer with another.
- This operator cannot be applied on float.
- On using ‘%‘ the sign of remainder is always same as of numerator.
Example :
5 % 2=1
-5 % 2=-1
5 % -2=1
-5 % -2=-1
- No operator is assumed to be present.It must be written explicitly.
Example :
a=c.d.b(x.y) (usual arithmetic expression)
a=c*d*b*(x*y) (C statement)
- There is no operator for performing exponentiation operation.
Example :
b= 3^ 2 is invalid statement.
If we want to do the exponentiation,we can get it done this way.
Code :
#include<math.h>
main()
{
int a;
a= pow (3,2); /*standard library function*/
printf(”%d”,a);
}
pow() function is being used to raise 3 to the power of 2.
written by Shweta
Jun 22
All the basic arithmetic operations can be carried out in C. All the operators have almost the same meaning as in other languages. Both unary and binary operations are available in C language. Unary operations operate on a singe operand, therefore the number 5 when operated by unary – will have the value .
Arithmetic Operators
|
Operator
|
Meaning
|
|
+
|
Addition or Unary Plus
|
|
–
|
Subtraction or Unary Minus
|
|
*
|
Multiplication
|
|
/
|
Division
|
|
%
|
Modulus Operator
|
Examples of arithmetic operators are
x + y
x – y
-x + y
a * b + c
-a * b
Here a, b, c, x, y are known as operands. The modulus operator is a special operator in C language which evaluates the remainder of the operands after division.
Integer Arithmetic
When an arithmetic operation is performed on two whole numbers or integers than such an operation is called as integer arithmetic. It always gives an integer as the result. Letx = 27 and y = 5 be 2 integer numbers. Then the integer operation leads to the following results.
x + y = 32
x – y = 22
x * y = 115
x % y = 2
x / y = 5
In integer division the fractional part is truncated.
Floating point arithmetic
When an arithmetic operation is preformed on two real numbers or fraction numbers such an operation is called floating point arithmetic. The floating point results can be truncated according to the properties requirement. The remainder operator is not applicable for floating point arithmetic operands.
Let x = 14.0 and y = 4.0 then
x + y = 18.0
x – y = 10.0
x * y = 56.0
x / y = 3.50
Mixed mode arithmetic
When one of the operand is real and other is an integer and if the arithmetic operation is carried out on these 2 operands then it is called as mixed mode arithmetic. If any one operand is of real type then the result will always be real thus 15/10.0 = 1.5
written by Shweta
\\ tags: Airthmetic OP
Recent Comments