SlideShare una empresa de Scribd logo
1 de 18
Lecture 3Lecture 3
Version 1.0Version 1.0
Arithmetic OperatorArithmetic Operator
Relational OperatorRelational Operator
Decision MakingDecision Making
KeywordsKeywords
2Rushdi Shams, Dept of CSE, KUET, Bangladesh
Arithmetic OperatorsArithmetic Operators
 Most C programs perform arithmetic calculationsMost C programs perform arithmetic calculations
3Rushdi Shams, Dept of CSE, KUET, Bangladesh
Arithmetic operatorsArithmetic operators
 The arithmetic operators are allThe arithmetic operators are all binary operatorsbinary operators
 The expression 3+7 contains binary operator +The expression 3+7 contains binary operator +
and twoand two operandsoperands 3 and 73 and 7
 Integer division yields an integer result. 17/4 is 4Integer division yields an integer result. 17/4 is 4
 The modulus operator means the remainderThe modulus operator means the remainder
after a division operation. 17%4 is 1after a division operation. 17%4 is 1
4Rushdi Shams, Dept of CSE, KUET, Bangladesh
Rules of Operator PrecedenceRules of Operator Precedence
1.1. Expressions or portion of expressionsExpressions or portion of expressions
contained in pairs of parentheses are evaluatedcontained in pairs of parentheses are evaluated
first. In case of nested parentheses, the innerfirst. In case of nested parentheses, the inner
most parentheses will be evaluated first.most parentheses will be evaluated first.
5Rushdi Shams, Dept of CSE, KUET, Bangladesh
Rules of Operator PrecedenceRules of Operator Precedence
2.2. Multiplication, division and modulusMultiplication, division and modulus
operations are evaluated next. If an expressionoperations are evaluated next. If an expression
contains several *, / or % operations,contains several *, / or % operations,
evaluations proceed from left to right. Theseevaluations proceed from left to right. These
operators are on the same level of precedence.operators are on the same level of precedence.
6Rushdi Shams, Dept of CSE, KUET, Bangladesh
Rules of Operator PrecedenceRules of Operator Precedence
3.3. Addition and subtraction are evaluated last. IfAddition and subtraction are evaluated last. If
an expression contains several + or -an expression contains several + or -
operations, evaluations proceed from left tooperations, evaluations proceed from left to
right.right.
7Rushdi Shams, Dept of CSE, KUET, Bangladesh
Brain Storm IBrain Storm I
 m=(a+b+c+d+e)/5m=(a+b+c+d+e)/5
 m=a+b+c+d+e/5m=a+b+c+d+e/5
 What are the differences here?What are the differences here?
8Rushdi Shams, Dept of CSE, KUET, Bangladesh
Brain Storm IIBrain Storm II
 y=mx+cy=mx+c
 How do you write this expression in C? AnyHow do you write this expression in C? Any
parenthesis required?parenthesis required?
9Rushdi Shams, Dept of CSE, KUET, Bangladesh
Brain Storm IIIBrain Storm III
 z=pr%q+w/x-yz=pr%q+w/x-y
 It is in algebraic format. How will it be written inIt is in algebraic format. How will it be written in
C? What will be the order of precedence givenC? What will be the order of precedence given
by the C compiler while it is written in Cby the C compiler while it is written in C
format?format?
10Rushdi Shams, Dept of CSE, KUET, Bangladesh
Decision Making: RelationalDecision Making: Relational
OperatorsOperators
 Executable C expressions either doExecutable C expressions either do actionsactions (calculations(calculations
or input or output) or make aor input or output) or make a decisiondecision
 For example, in a program where the user will put hisFor example, in a program where the user will put his
mark and want to know if he passed or failed, you willmark and want to know if he passed or failed, you will
have to do three things-have to do three things-
1. Take the mark from the user.1. Take the mark from the user. ActionAction
2. Compare the mark with a predefined pass mark range.2. Compare the mark with a predefined pass mark range.
DecisionDecision
3. Provide that decision to user.3. Provide that decision to user. ActionAction
11Rushdi Shams, Dept of CSE, KUET, Bangladesh
Decision Making: RelationalDecision Making: Relational
OperatorsOperators
 The decision in C is done by a control structureThe decision in C is done by a control structure
calledcalled ifif
 It allows a program to make a decision based onIt allows a program to make a decision based on
the truth or falsity of some statement of factthe truth or falsity of some statement of fact
calledcalled conditioncondition
 If the condition is true,If the condition is true, the body statementthe body statement will bewill be
executed otherwise not- it will execute the nextexecuted otherwise not- it will execute the next
statement after thestatement after the ifif structurestructure
12Rushdi Shams, Dept of CSE, KUET, Bangladesh
Decision Making: RelationalDecision Making: Relational
OperatorsOperators
 Conditions inConditions in ifif structures are formed by usingstructures are formed by using
relational operatorsrelational operators
 The relational operators have the same level ofThe relational operators have the same level of
precedence and they associate left to rightprecedence and they associate left to right
 OnlyOnly equality operatorsequality operators have a lower level ofhave a lower level of
precedence than others and they also associateprecedence than others and they also associate
left to rightleft to right
13Rushdi Shams, Dept of CSE, KUET, Bangladesh
Decision Making: RelationalDecision Making: Relational
OperatorsOperators
14Rushdi Shams, Dept of CSE, KUET, Bangladesh
Decision Making: RelationalDecision Making: Relational
OperatorsOperators
 There is a subtle difference between == and =.There is a subtle difference between == and =.
In case of =, it is associated from right to left.In case of =, it is associated from right to left.
a=b means the value of b is assigned to aa=b means the value of b is assigned to a
15Rushdi Shams, Dept of CSE, KUET, Bangladesh
Decision Making: RelationalDecision Making: Relational
OperatorsOperators
#include <stdio.h>#include <stdio.h>
#include <conio.h>#include <conio.h>
void main(){void main(){
clrscr();clrscr();
int num1, num2;int num1, num2;
printf(“Enter two numbers to compare: ”);printf(“Enter two numbers to compare: ”);
scanf(“%d %d”, &num1, &num2);scanf(“%d %d”, &num1, &num2);
if(num1 == num2)if(num1 == num2)
printf(“%d and %d are equal”, num1, num2);printf(“%d and %d are equal”, num1, num2);
if(num1 != num2)if(num1 != num2)
printf(“%d and %d are not equal”, num1, num2);printf(“%d and %d are not equal”, num1, num2);
if(num1 < num2)if(num1 < num2)
printf(“%d is less than %d”, num1, num2);printf(“%d is less than %d”, num1, num2);
if(num1 > num2)if(num1 > num2)
printf(“%d is greater than %d”, num1, num2);printf(“%d is greater than %d”, num1, num2);
if(num1 <= num2)if(num1 <= num2)
printf(“%d is less than or equal to %d”, num1, num2);printf(“%d is less than or equal to %d”, num1, num2);
if(num1 >= num2)if(num1 >= num2)
printf(“%d is greater than or equal to %d”, num1, num2);printf(“%d is greater than or equal to %d”, num1, num2);
getch();getch();
}}
16Rushdi Shams, Dept of CSE, KUET, Bangladesh
KeywordsKeywords
 intint andand ifif areare keywordskeywords oror reserved wordsreserved words in Cin C
 You cannot use them as variable names as CYou cannot use them as variable names as C
compiler processes keywords in a different waycompiler processes keywords in a different way
17Rushdi Shams, Dept of CSE, KUET, Bangladesh
KeywordsKeywords
18Rushdi Shams, Dept of CSE, KUET, Bangladesh
QsQs
1.1. Every C program must have a function. What is its name?Every C program must have a function. What is its name?
2.2. What symbols are used to contain the body of the function?What symbols are used to contain the body of the function?
3.3. With what symbol every statement ends with?With what symbol every statement ends with?
4.4. Which function displays information on the screen? WhichWhich function displays information on the screen? Which
header file is required for that function?header file is required for that function?
5.5. What does n represents?What does n represents?
6.6. Which function takes input from the user?Which function takes input from the user?
7.7. Which specifier is required to represent integer?Which specifier is required to represent integer?
8.8. Which keyword is used to make decision?Which keyword is used to make decision?
9.9. What are used to make a program readable?What are used to make a program readable?

Más contenido relacionado

Destacado

Chapter 2 instructions language of the computer
Chapter 2 instructions language of the computerChapter 2 instructions language of the computer
Chapter 2 instructions language of the computer
BATMUNHMUNHZAYA
 
Looping statements in C
Looping statements in CLooping statements in C
Looping statements in C
Jeya Lakshmi
 
Computer Languages....ppt
Computer Languages....pptComputer Languages....ppt
Computer Languages....ppt
hashgeneration
 
Lect 1. introduction to programming languages
Lect 1. introduction to programming languagesLect 1. introduction to programming languages
Lect 1. introduction to programming languages
Varun Garg
 

Destacado (12)

C language control statements
C language  control statementsC language  control statements
C language control statements
 
C –imp points
C –imp pointsC –imp points
C –imp points
 
Control structure in c
Control structure in cControl structure in c
Control structure in c
 
Chapter 2 instructions language of the computer
Chapter 2 instructions language of the computerChapter 2 instructions language of the computer
Chapter 2 instructions language of the computer
 
Looping statements in C
Looping statements in CLooping statements in C
Looping statements in C
 
Abc & Ved
Abc & VedAbc & Ved
Abc & Ved
 
Computer Languages....ppt
Computer Languages....pptComputer Languages....ppt
Computer Languages....ppt
 
Programming languages
Programming languagesProgramming languages
Programming languages
 
Computer Languages.
Computer Languages.Computer Languages.
Computer Languages.
 
Operator in c programming
Operator in c programmingOperator in c programming
Operator in c programming
 
C language ppt
C language pptC language ppt
C language ppt
 
Lect 1. introduction to programming languages
Lect 1. introduction to programming languagesLect 1. introduction to programming languages
Lect 1. introduction to programming languages
 

Similar a Lec 03. Arithmetic Operator / Relational Operator

Lec 05. While Loop
Lec 05. While LoopLec 05. While Loop
Lec 05. While Loop
Rushdi Shams
 
Lec 10. Functions (Part II)
Lec 10. Functions (Part II)Lec 10. Functions (Part II)
Lec 10. Functions (Part II)
Rushdi Shams
 
Lec 02. C Program Structure / C Memory Concept
Lec 02. C Program Structure / C Memory ConceptLec 02. C Program Structure / C Memory Concept
Lec 02. C Program Structure / C Memory Concept
Rushdi Shams
 
C Prog. - Operators and Expressions
C Prog. - Operators and ExpressionsC Prog. - Operators and Expressions
C Prog. - Operators and Expressions
vinay arora
 
Lec 07. Do-While Loop / Switch
Lec 07. Do-While Loop / SwitchLec 07. Do-While Loop / Switch
Lec 07. Do-While Loop / Switch
Rushdi Shams
 
Iaetsd protecting privacy preserving for cost effective adaptive actions
Iaetsd protecting  privacy preserving for cost effective adaptive actionsIaetsd protecting  privacy preserving for cost effective adaptive actions
Iaetsd protecting privacy preserving for cost effective adaptive actions
Iaetsd Iaetsd
 
Lec 04. If-Else Statement / Increment and Decrement Operators
Lec 04. If-Else Statement / Increment and Decrement OperatorsLec 04. If-Else Statement / Increment and Decrement Operators
Lec 04. If-Else Statement / Increment and Decrement Operators
Rushdi Shams
 
Overview of a Self-Adaptive Workflow System
Overview of a Self-Adaptive Workflow SystemOverview of a Self-Adaptive Workflow System
Overview of a Self-Adaptive Workflow System
Luca Sabatucci
 

Similar a Lec 03. Arithmetic Operator / Relational Operator (20)

Lec 05. While Loop
Lec 05. While LoopLec 05. While Loop
Lec 05. While Loop
 
The Three Basic Selection Structures in C++ Programming Concepts
The Three Basic Selection Structures in C++ Programming ConceptsThe Three Basic Selection Structures in C++ Programming Concepts
The Three Basic Selection Structures in C++ Programming Concepts
 
C programming
C programmingC programming
C programming
 
Lec 10. Functions (Part II)
Lec 10. Functions (Part II)Lec 10. Functions (Part II)
Lec 10. Functions (Part II)
 
Lec 02. C Program Structure / C Memory Concept
Lec 02. C Program Structure / C Memory ConceptLec 02. C Program Structure / C Memory Concept
Lec 02. C Program Structure / C Memory Concept
 
Unit1
Unit1Unit1
Unit1
 
C Prog. - Operators and Expressions
C Prog. - Operators and ExpressionsC Prog. - Operators and Expressions
C Prog. - Operators and Expressions
 
Lec 07. Do-While Loop / Switch
Lec 07. Do-While Loop / SwitchLec 07. Do-While Loop / Switch
Lec 07. Do-While Loop / Switch
 
Introduction to algorithms
Introduction to algorithmsIntroduction to algorithms
Introduction to algorithms
 
Basic of Programming (Introduction to Programming)
Basic of Programming (Introduction to Programming)Basic of Programming (Introduction to Programming)
Basic of Programming (Introduction to Programming)
 
Object Oriented Programming Short Notes for Preperation of Exams
Object Oriented Programming Short Notes for Preperation of ExamsObject Oriented Programming Short Notes for Preperation of Exams
Object Oriented Programming Short Notes for Preperation of Exams
 
jhtp9_ch04.ppt
jhtp9_ch04.pptjhtp9_ch04.ppt
jhtp9_ch04.ppt
 
Unit 2
Unit 2Unit 2
Unit 2
 
Iaetsd protecting privacy preserving for cost effective adaptive actions
Iaetsd protecting  privacy preserving for cost effective adaptive actionsIaetsd protecting  privacy preserving for cost effective adaptive actions
Iaetsd protecting privacy preserving for cost effective adaptive actions
 
Lec 04. If-Else Statement / Increment and Decrement Operators
Lec 04. If-Else Statement / Increment and Decrement OperatorsLec 04. If-Else Statement / Increment and Decrement Operators
Lec 04. If-Else Statement / Increment and Decrement Operators
 
Java Programming Materials
Java Programming MaterialsJava Programming Materials
Java Programming Materials
 
IRJET- Personality Prediction System using AI
IRJET- Personality Prediction System using AIIRJET- Personality Prediction System using AI
IRJET- Personality Prediction System using AI
 
slides03.ppt
slides03.pptslides03.ppt
slides03.ppt
 
Overview of a Self-Adaptive Workflow System
Overview of a Self-Adaptive Workflow SystemOverview of a Self-Adaptive Workflow System
Overview of a Self-Adaptive Workflow System
 
Fuzzy logic
Fuzzy logicFuzzy logic
Fuzzy logic
 

Más de Rushdi Shams

Types of machine translation
Types of machine translationTypes of machine translation
Types of machine translation
Rushdi Shams
 
L1 l2 l3 introduction to machine translation
L1 l2 l3  introduction to machine translationL1 l2 l3  introduction to machine translation
L1 l2 l3 introduction to machine translation
Rushdi Shams
 
Syntax and semantics
Syntax and semanticsSyntax and semantics
Syntax and semantics
Rushdi Shams
 
Propositional logic
Propositional logicPropositional logic
Propositional logic
Rushdi Shams
 
Probabilistic logic
Probabilistic logicProbabilistic logic
Probabilistic logic
Rushdi Shams
 
Knowledge structure
Knowledge structureKnowledge structure
Knowledge structure
Rushdi Shams
 
Knowledge representation
Knowledge representationKnowledge representation
Knowledge representation
Rushdi Shams
 
L5 understanding hacking
L5  understanding hackingL5  understanding hacking
L5 understanding hacking
Rushdi Shams
 
L2 Intrusion Detection System (IDS)
L2  Intrusion Detection System (IDS)L2  Intrusion Detection System (IDS)
L2 Intrusion Detection System (IDS)
Rushdi Shams
 

Más de Rushdi Shams (20)

Research Methodology and Tips on Better Research
Research Methodology and Tips on Better ResearchResearch Methodology and Tips on Better Research
Research Methodology and Tips on Better Research
 
Common evaluation measures in NLP and IR
Common evaluation measures in NLP and IRCommon evaluation measures in NLP and IR
Common evaluation measures in NLP and IR
 
Machine learning with nlp 101
Machine learning with nlp 101Machine learning with nlp 101
Machine learning with nlp 101
 
Semi-supervised classification for natural language processing
Semi-supervised classification for natural language processingSemi-supervised classification for natural language processing
Semi-supervised classification for natural language processing
 
Natural Language Processing: Parsing
Natural Language Processing: ParsingNatural Language Processing: Parsing
Natural Language Processing: Parsing
 
Types of machine translation
Types of machine translationTypes of machine translation
Types of machine translation
 
L1 l2 l3 introduction to machine translation
L1 l2 l3  introduction to machine translationL1 l2 l3  introduction to machine translation
L1 l2 l3 introduction to machine translation
 
Syntax and semantics
Syntax and semanticsSyntax and semantics
Syntax and semantics
 
Propositional logic
Propositional logicPropositional logic
Propositional logic
 
Probabilistic logic
Probabilistic logicProbabilistic logic
Probabilistic logic
 
L15 fuzzy logic
L15  fuzzy logicL15  fuzzy logic
L15 fuzzy logic
 
Knowledge structure
Knowledge structureKnowledge structure
Knowledge structure
 
Knowledge representation
Knowledge representationKnowledge representation
Knowledge representation
 
First order logic
First order logicFirst order logic
First order logic
 
Belief function
Belief functionBelief function
Belief function
 
L5 understanding hacking
L5  understanding hackingL5  understanding hacking
L5 understanding hacking
 
L4 vpn
L4  vpnL4  vpn
L4 vpn
 
L3 defense
L3  defenseL3  defense
L3 defense
 
L2 Intrusion Detection System (IDS)
L2  Intrusion Detection System (IDS)L2  Intrusion Detection System (IDS)
L2 Intrusion Detection System (IDS)
 
L1 phishing
L1  phishingL1  phishing
L1 phishing
 

Último

The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
KarakKing
 

Último (20)

How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptx
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 

Lec 03. Arithmetic Operator / Relational Operator

  • 1. Lecture 3Lecture 3 Version 1.0Version 1.0 Arithmetic OperatorArithmetic Operator Relational OperatorRelational Operator Decision MakingDecision Making KeywordsKeywords
  • 2. 2Rushdi Shams, Dept of CSE, KUET, Bangladesh Arithmetic OperatorsArithmetic Operators  Most C programs perform arithmetic calculationsMost C programs perform arithmetic calculations
  • 3. 3Rushdi Shams, Dept of CSE, KUET, Bangladesh Arithmetic operatorsArithmetic operators  The arithmetic operators are allThe arithmetic operators are all binary operatorsbinary operators  The expression 3+7 contains binary operator +The expression 3+7 contains binary operator + and twoand two operandsoperands 3 and 73 and 7  Integer division yields an integer result. 17/4 is 4Integer division yields an integer result. 17/4 is 4  The modulus operator means the remainderThe modulus operator means the remainder after a division operation. 17%4 is 1after a division operation. 17%4 is 1
  • 4. 4Rushdi Shams, Dept of CSE, KUET, Bangladesh Rules of Operator PrecedenceRules of Operator Precedence 1.1. Expressions or portion of expressionsExpressions or portion of expressions contained in pairs of parentheses are evaluatedcontained in pairs of parentheses are evaluated first. In case of nested parentheses, the innerfirst. In case of nested parentheses, the inner most parentheses will be evaluated first.most parentheses will be evaluated first.
  • 5. 5Rushdi Shams, Dept of CSE, KUET, Bangladesh Rules of Operator PrecedenceRules of Operator Precedence 2.2. Multiplication, division and modulusMultiplication, division and modulus operations are evaluated next. If an expressionoperations are evaluated next. If an expression contains several *, / or % operations,contains several *, / or % operations, evaluations proceed from left to right. Theseevaluations proceed from left to right. These operators are on the same level of precedence.operators are on the same level of precedence.
  • 6. 6Rushdi Shams, Dept of CSE, KUET, Bangladesh Rules of Operator PrecedenceRules of Operator Precedence 3.3. Addition and subtraction are evaluated last. IfAddition and subtraction are evaluated last. If an expression contains several + or -an expression contains several + or - operations, evaluations proceed from left tooperations, evaluations proceed from left to right.right.
  • 7. 7Rushdi Shams, Dept of CSE, KUET, Bangladesh Brain Storm IBrain Storm I  m=(a+b+c+d+e)/5m=(a+b+c+d+e)/5  m=a+b+c+d+e/5m=a+b+c+d+e/5  What are the differences here?What are the differences here?
  • 8. 8Rushdi Shams, Dept of CSE, KUET, Bangladesh Brain Storm IIBrain Storm II  y=mx+cy=mx+c  How do you write this expression in C? AnyHow do you write this expression in C? Any parenthesis required?parenthesis required?
  • 9. 9Rushdi Shams, Dept of CSE, KUET, Bangladesh Brain Storm IIIBrain Storm III  z=pr%q+w/x-yz=pr%q+w/x-y  It is in algebraic format. How will it be written inIt is in algebraic format. How will it be written in C? What will be the order of precedence givenC? What will be the order of precedence given by the C compiler while it is written in Cby the C compiler while it is written in C format?format?
  • 10. 10Rushdi Shams, Dept of CSE, KUET, Bangladesh Decision Making: RelationalDecision Making: Relational OperatorsOperators  Executable C expressions either doExecutable C expressions either do actionsactions (calculations(calculations or input or output) or make aor input or output) or make a decisiondecision  For example, in a program where the user will put hisFor example, in a program where the user will put his mark and want to know if he passed or failed, you willmark and want to know if he passed or failed, you will have to do three things-have to do three things- 1. Take the mark from the user.1. Take the mark from the user. ActionAction 2. Compare the mark with a predefined pass mark range.2. Compare the mark with a predefined pass mark range. DecisionDecision 3. Provide that decision to user.3. Provide that decision to user. ActionAction
  • 11. 11Rushdi Shams, Dept of CSE, KUET, Bangladesh Decision Making: RelationalDecision Making: Relational OperatorsOperators  The decision in C is done by a control structureThe decision in C is done by a control structure calledcalled ifif  It allows a program to make a decision based onIt allows a program to make a decision based on the truth or falsity of some statement of factthe truth or falsity of some statement of fact calledcalled conditioncondition  If the condition is true,If the condition is true, the body statementthe body statement will bewill be executed otherwise not- it will execute the nextexecuted otherwise not- it will execute the next statement after thestatement after the ifif structurestructure
  • 12. 12Rushdi Shams, Dept of CSE, KUET, Bangladesh Decision Making: RelationalDecision Making: Relational OperatorsOperators  Conditions inConditions in ifif structures are formed by usingstructures are formed by using relational operatorsrelational operators  The relational operators have the same level ofThe relational operators have the same level of precedence and they associate left to rightprecedence and they associate left to right  OnlyOnly equality operatorsequality operators have a lower level ofhave a lower level of precedence than others and they also associateprecedence than others and they also associate left to rightleft to right
  • 13. 13Rushdi Shams, Dept of CSE, KUET, Bangladesh Decision Making: RelationalDecision Making: Relational OperatorsOperators
  • 14. 14Rushdi Shams, Dept of CSE, KUET, Bangladesh Decision Making: RelationalDecision Making: Relational OperatorsOperators  There is a subtle difference between == and =.There is a subtle difference between == and =. In case of =, it is associated from right to left.In case of =, it is associated from right to left. a=b means the value of b is assigned to aa=b means the value of b is assigned to a
  • 15. 15Rushdi Shams, Dept of CSE, KUET, Bangladesh Decision Making: RelationalDecision Making: Relational OperatorsOperators #include <stdio.h>#include <stdio.h> #include <conio.h>#include <conio.h> void main(){void main(){ clrscr();clrscr(); int num1, num2;int num1, num2; printf(“Enter two numbers to compare: ”);printf(“Enter two numbers to compare: ”); scanf(“%d %d”, &num1, &num2);scanf(“%d %d”, &num1, &num2); if(num1 == num2)if(num1 == num2) printf(“%d and %d are equal”, num1, num2);printf(“%d and %d are equal”, num1, num2); if(num1 != num2)if(num1 != num2) printf(“%d and %d are not equal”, num1, num2);printf(“%d and %d are not equal”, num1, num2); if(num1 < num2)if(num1 < num2) printf(“%d is less than %d”, num1, num2);printf(“%d is less than %d”, num1, num2); if(num1 > num2)if(num1 > num2) printf(“%d is greater than %d”, num1, num2);printf(“%d is greater than %d”, num1, num2); if(num1 <= num2)if(num1 <= num2) printf(“%d is less than or equal to %d”, num1, num2);printf(“%d is less than or equal to %d”, num1, num2); if(num1 >= num2)if(num1 >= num2) printf(“%d is greater than or equal to %d”, num1, num2);printf(“%d is greater than or equal to %d”, num1, num2); getch();getch(); }}
  • 16. 16Rushdi Shams, Dept of CSE, KUET, Bangladesh KeywordsKeywords  intint andand ifif areare keywordskeywords oror reserved wordsreserved words in Cin C  You cannot use them as variable names as CYou cannot use them as variable names as C compiler processes keywords in a different waycompiler processes keywords in a different way
  • 17. 17Rushdi Shams, Dept of CSE, KUET, Bangladesh KeywordsKeywords
  • 18. 18Rushdi Shams, Dept of CSE, KUET, Bangladesh QsQs 1.1. Every C program must have a function. What is its name?Every C program must have a function. What is its name? 2.2. What symbols are used to contain the body of the function?What symbols are used to contain the body of the function? 3.3. With what symbol every statement ends with?With what symbol every statement ends with? 4.4. Which function displays information on the screen? WhichWhich function displays information on the screen? Which header file is required for that function?header file is required for that function? 5.5. What does n represents?What does n represents? 6.6. Which function takes input from the user?Which function takes input from the user? 7.7. Which specifier is required to represent integer?Which specifier is required to represent integer? 8.8. Which keyword is used to make decision?Which keyword is used to make decision? 9.9. What are used to make a program readable?What are used to make a program readable?