"Z Code Writer" is an Online Blog for Programmer & Beginner. Here, You will Find tech, Build your Programming Skills and other Programming Language Like C, C++, HTML, Java Script Java Code, Web Designing and University Of Sialkot (USKT) CGPA / GPA Calculator etc.

Thursday, 4 July 2019

Arithmetic Operators

Arithmetic Operators

          The operators that are used to perform arithmetic operations on numeric values are known as arithmetic operators. These operators are used with variables and constants to form arithmetic expressions. The basic arithmetic operators that are available in C are:
                                           
Operation
Operator
Purpose
Addition
+
It is used to add two values.
Subtraction
-
It is used to subtract one value from another value.
Multiplication
*
it is used to multiply two values.
Division
/
It is used to divide one value from another value.
Modulus
%
It is used to find remainder of division of two integers.

          All arithmetic operators, except the modulus (%) operator are used to perform arithmetic operations on real as well as integer type data. The modulus operator (%) can only be used to perform division on integer type values. For example, 7%4 returns the remainder 3. The modulus operator is also called remainder operator.
Each arithmetic operator performs arithmetic operation on two numeric values (constant or variables). So arithmetic operators are binary operators.

Working with Division Operator

          In C, the division operation is slightly different than other arithmetic operations. When the divisor and the dividend both are integer values, the fractional part of the quotient is truncated. For example, the returned value by the 5.0/ 2.0 is 2.5 but the returned value of 5/2 is 2. Similarly the returned value of 98.0/100.0 is 0.98 but the returned value of 98/100 is 0.
Therefore, to get the accurate result at least one floating-point number should be used in the division operation. Otherwise integral division will take place and integral part of the division is returned.

Expressions

          An expression is the combination of operators and operands. The operands are the values on which operators perform the operations. The operands maybe variables, constants or combination of both. Parenthesis can also be used in an expression. An expression gives a single result.
For example, to compute the volume of a box with sides a, b, and c, the mathematical expression is written as;
                     a  *  b  *  c
Where a, b and c are variables and are called operands. The multiplication sign '*' is called operator.
The expressions are divided into the following main categories:


  1. arithmetic expressions
  2. relational expressions
  3. logical expressions

Arithmetic Expressions

          An expression that is combination of numeric variables, numeric constants and arithmetic operators is called arithmetic expressions. In a C program, the arithmetic expression is used to calculate the value of an arithmetic formula. The arithmetic expression is evaluated and single value is returned.
some examples of arithmetic expressions are:


  1.  a  +  b
  2.  a  *  5  +  b
        In the above expression "a  +  b", the special symbol '+' is the arithmetic operator while 'a' and 'b' are operands.
For example, if a = 9 and b = 6 are 'int' type values. The following table shows the arithmetic expressions and their outputs: 
                                         
Expression
Output
a + b
a – b
a * b
a / b
a % b
15
3
54
1
3

No comments:

Post a Comment

Thanks For Visiting Here...!! I will Reply you as soon as possible.