Operators and conditional statements in C
28/9/2021 A.Chandran ACE Learning Hub, chandkec#gmail.com 1
Learning Hub
Erode 638 011
Mob:93600 48588
chandkec@gmail.co
m
ACE Learning Hub
Erode 638 011
Mob:93600 48588
chandkec@gmail.com
Operators:
• An operator is a symbol that tells the compiler to perform a certain
mathematical or logical manipulation.
• Operators are used in programs to manipulate data and variables.
The various types of operators:
1) Arithmetic operators (+, -, *, /, %)
2) Assignment operators (=)
3) Relational /Comparison operators (>, =, <=, ==,!=)
4) Increment and Decrement operators (++, - -)
28/9/2021 A.Chandran ACE Learning Hub, chandkec#gmail.com 3
(i)Arithmetic operators:
An arithmetic operator performs mathematical operations such as
addition, subtraction, multiplication, division etc on numerical values
(constants and variables).
28/9/2021 A.Chandran ACE Learning Hub, chandkec#gmail.com 4
28/9/2021 A.Chandran ACE Learning Hub, chandkec#gmail.com 5
28/9/2021 A.Chandran ACE Learning Hub, chandkec#gmail.com 6
28/9/2021 A.Chandran ACE Learning Hub, chandkec#gmail.com 7
(iv) Relational or comparison operators:
• Relational operators are used to compare values of two expressions.
Relational operators are binary operators because they require two
operands to operate.
• An expression which contains the relational operators is called
relational expression.
• If the relation is true then the result of the relational expression is
1, if the relation is false then the result of the relational expression
is 0.
28/9/2021 A.Chandran ACE Learning Hub, chandkec#gmail.com 8
28/9/2021 A.Chandran ACE Learning Hub, chandkec#gmail.com 9
28/9/2021 A.Chandran ACE Learning Hub, chandkec#gmail.com 10
28/9/2021 A.Chandran ACE Learning Hub, chandkec#gmail.com 11
28/9/2021 A.Chandran ACE Learning Hub, chandkec#gmail.com 12
Conditional statements in C:
(i) Simple IF statement:
• It contains only the true statement and its condition.
• The statements inside the body of “if” only execute if the given
condition returns true.
• If the condition returns false then the statements inside “if” are
skipped
28/9/2021 A.Chandran ACE Learning Hub, chandkec#gmail.com 13
28/9/2021 A.Chandran ACE Learning Hub, chandkec#gmail.com 14
28/9/2021 A.Chandran ACE Learning Hub, chandkec#gmail.com 15
(ii) IF..Else statements :
• It contains both the true and false statements along with its condition.
IF condition returns true then the statements inside the body of “IF”
are executed and the statements inside body of “else” are skipped.
• IF condition returns false then the statements inside the body of “IF”
are skipped and the statements in “else” are executed.
28/9/2021 A.Chandran ACE Learning Hub, chandkec#gmail.com 16
28/9/2021 A.Chandran ACE Learning Hub, chandkec#gmail.com 17
• In this program user is asked to enter the age and based on the input, the
if..else statement checks whether the entered age is greater than or
equal to 18.
• If this condition is met, then display message “You are eligible for
voting”, however if the condition isn’t met, then display a different
message “You are not eligible for voting”.
28/9/2021 A.Chandran ACE Learning Hub, chandkec#gmail.com 18
28/9/2021 A.Chandran ACE Learning Hub, chandkec#gmail.com 19
28/9/2021 A.Chandran ACE Learning Hub, chandkec#gmail.com 20

Operators and Conditional statements in C

  • 1.
    Operators and conditionalstatements in C 28/9/2021 A.Chandran ACE Learning Hub, chandkec#gmail.com 1 Learning Hub Erode 638 011 Mob:93600 48588 chandkec@gmail.co m
  • 2.
    ACE Learning Hub Erode638 011 Mob:93600 48588 chandkec@gmail.com
  • 3.
    Operators: • An operatoris a symbol that tells the compiler to perform a certain mathematical or logical manipulation. • Operators are used in programs to manipulate data and variables. The various types of operators: 1) Arithmetic operators (+, -, *, /, %) 2) Assignment operators (=) 3) Relational /Comparison operators (>, =, <=, ==,!=) 4) Increment and Decrement operators (++, - -) 28/9/2021 A.Chandran ACE Learning Hub, chandkec#gmail.com 3
  • 4.
    (i)Arithmetic operators: An arithmeticoperator performs mathematical operations such as addition, subtraction, multiplication, division etc on numerical values (constants and variables). 28/9/2021 A.Chandran ACE Learning Hub, chandkec#gmail.com 4
  • 5.
    28/9/2021 A.Chandran ACELearning Hub, chandkec#gmail.com 5
  • 6.
    28/9/2021 A.Chandran ACELearning Hub, chandkec#gmail.com 6
  • 7.
    28/9/2021 A.Chandran ACELearning Hub, chandkec#gmail.com 7
  • 8.
    (iv) Relational orcomparison operators: • Relational operators are used to compare values of two expressions. Relational operators are binary operators because they require two operands to operate. • An expression which contains the relational operators is called relational expression. • If the relation is true then the result of the relational expression is 1, if the relation is false then the result of the relational expression is 0. 28/9/2021 A.Chandran ACE Learning Hub, chandkec#gmail.com 8
  • 9.
    28/9/2021 A.Chandran ACELearning Hub, chandkec#gmail.com 9
  • 10.
    28/9/2021 A.Chandran ACELearning Hub, chandkec#gmail.com 10
  • 11.
    28/9/2021 A.Chandran ACELearning Hub, chandkec#gmail.com 11
  • 12.
    28/9/2021 A.Chandran ACELearning Hub, chandkec#gmail.com 12 Conditional statements in C: (i) Simple IF statement: • It contains only the true statement and its condition. • The statements inside the body of “if” only execute if the given condition returns true. • If the condition returns false then the statements inside “if” are skipped
  • 13.
    28/9/2021 A.Chandran ACELearning Hub, chandkec#gmail.com 13
  • 14.
    28/9/2021 A.Chandran ACELearning Hub, chandkec#gmail.com 14
  • 15.
    28/9/2021 A.Chandran ACELearning Hub, chandkec#gmail.com 15 (ii) IF..Else statements : • It contains both the true and false statements along with its condition. IF condition returns true then the statements inside the body of “IF” are executed and the statements inside body of “else” are skipped. • IF condition returns false then the statements inside the body of “IF” are skipped and the statements in “else” are executed.
  • 16.
    28/9/2021 A.Chandran ACELearning Hub, chandkec#gmail.com 16
  • 17.
    28/9/2021 A.Chandran ACELearning Hub, chandkec#gmail.com 17 • In this program user is asked to enter the age and based on the input, the if..else statement checks whether the entered age is greater than or equal to 18. • If this condition is met, then display message “You are eligible for voting”, however if the condition isn’t met, then display a different message “You are not eligible for voting”.
  • 18.
    28/9/2021 A.Chandran ACELearning Hub, chandkec#gmail.com 18
  • 19.
    28/9/2021 A.Chandran ACELearning Hub, chandkec#gmail.com 19
  • 20.
    28/9/2021 A.Chandran ACELearning Hub, chandkec#gmail.com 20