Government polytechnic
Dehradun
TOPIC:- C Arithmetic Operators
PREPARED By- Gaurav
Nautiyal
▪ Operators are symbols which take one or more
operands or expressions and perform arithmetic or
logical computations.
▪ Operands are variables or expressions which are
used in conjunction with operators to evaluate the
expression.
▪ Combination of operands and operators form an
expression.
OPERATORS
ARITHMETIC OPERATORS
oThese are “Binary Operators” as they take two
operands.
o The operands must be ”Numeric Value”.
oWhen both the operands are integer , then the
result is integer. But when one of them is floating
point and other is integer then the result is floating
point.
oExcept “% ” operators, all the arithmetic operators
can be used with any type of numeric operands(either
operands are integer or floating point), while “%”
operator can only be used with integer data type only.
Expressions
Example 2 * y + 5
Operands
Combination of Operators and Operands
Operators
TYPES OF OPERATORS
-C language provides following operators:-
Arithmetic Operators
oAs the name is given, arithmetic operators perform
arithmetic operations.
o C language provides following arithmetic operators.
Operator name Meaning
+ Addition
- Subtraction
* Multiplication
/ Division
% Modulus(Reminder after division)
Operator Precedence and Associativity in
C
The concept of operator precedence and
associativity in C helps in determining which
operators will be given priority when there
are multiple operators in the expression. It
is very common to have multiple operators in
C language and the compiler first evaluates
the operater with higher precedence. It
helps to maintain the ambiguity of the
expression and helps us in avoiding
unnecessary use of parenthesis.
Example of Operator Precedence
Associativity in C
Operator precedence determines which operation
is performed first in an expression with more
than one operator with different precedence.
Example
SMALL EXAMPLE TO ILLUSTRATE THE
USE OFARITHMETIC OPERATORS
#include<stdio.h>
#include<conio.h>
Void main()
{
float a=4,b=2,sum,sub,mul,div;
clrscr();
sum=a+b;
sub=a-b;
mul=a*b;
div=a/b;
printf(“summation of a and b=%fnsubtractionof and b=
%fnmultiplicationof and b=%fndivision of a and b=
%f,sum,sub,mul,div”);
getch();
}
Output of the following code will be like this:
summation of a and b=6.000000
subtraction of a and b=2.000000
multiplication of a and b=8.000000
division of a and b=2.000000
programing in c PPT Gaurav Nautiyal.pptx

programing in c PPT Gaurav Nautiyal.pptx

  • 1.
    Government polytechnic Dehradun TOPIC:- CArithmetic Operators PREPARED By- Gaurav Nautiyal
  • 2.
    ▪ Operators aresymbols which take one or more operands or expressions and perform arithmetic or logical computations. ▪ Operands are variables or expressions which are used in conjunction with operators to evaluate the expression. ▪ Combination of operands and operators form an expression. OPERATORS
  • 3.
    ARITHMETIC OPERATORS oThese are“Binary Operators” as they take two operands. o The operands must be ”Numeric Value”. oWhen both the operands are integer , then the result is integer. But when one of them is floating point and other is integer then the result is floating point. oExcept “% ” operators, all the arithmetic operators can be used with any type of numeric operands(either operands are integer or floating point), while “%” operator can only be used with integer data type only.
  • 4.
    Expressions Example 2 *y + 5 Operands Combination of Operators and Operands Operators
  • 5.
    TYPES OF OPERATORS -Clanguage provides following operators:-
  • 6.
    Arithmetic Operators oAs thename is given, arithmetic operators perform arithmetic operations. o C language provides following arithmetic operators. Operator name Meaning + Addition - Subtraction * Multiplication / Division % Modulus(Reminder after division)
  • 7.
    Operator Precedence andAssociativity in C The concept of operator precedence and associativity in C helps in determining which operators will be given priority when there are multiple operators in the expression. It is very common to have multiple operators in C language and the compiler first evaluates the operater with higher precedence. It helps to maintain the ambiguity of the expression and helps us in avoiding unnecessary use of parenthesis.
  • 9.
  • 10.
    Associativity in C Operatorprecedence determines which operation is performed first in an expression with more than one operator with different precedence. Example
  • 11.
    SMALL EXAMPLE TOILLUSTRATE THE USE OFARITHMETIC OPERATORS #include<stdio.h> #include<conio.h> Void main() { float a=4,b=2,sum,sub,mul,div; clrscr(); sum=a+b; sub=a-b; mul=a*b; div=a/b; printf(“summation of a and b=%fnsubtractionof and b= %fnmultiplicationof and b=%fndivision of a and b= %f,sum,sub,mul,div”); getch(); }
  • 12.
    Output of thefollowing code will be like this: summation of a and b=6.000000 subtraction of a and b=2.000000 multiplication of a and b=8.000000 division of a and b=2.000000