SlideShare una empresa de Scribd logo
1 de 22
Descargar para leer sin conexión
B Y
Y N D ARAVIND
A S S O C I A T E P R O F E S S O R , D E P T O F C S E
N E W T O N ’ S G R O U P O F I N S T I T U T I O N S , M A C H E R L A
@2020 Presented By Mr.Y N D Aravind
1
SELECTION – MAKING
DECISIONS
P A R T - I I
L O G I C A L D A T A A N D O P E R A T O R S
T W O W A Y S E L E C T I O N
M U L T I W A Y S E L E C T I O N
M O R E S T A N D A R D F U N C T I O N S
@2020 Presented By Mr.Y N D Aravind
2
SELECTION – MAKING DECISIONS
Logical Data and Operators
Presented By Mr.Y N D Aravind
3
A piece of data is called logical if it gives information as true or
false.
For this, we have boolean data type called _bool, declared as
unsigned integer in stdbool.h file.
To support logical data we have to use bool type. Logical
operators are used to combine two or more relations.
The logical operators are called Boolean operators. Because the
test between values are reduced to either true or false, with
zero being false and one being true.
Logical Data and Operators
Presented By Mr.Y N D Aravind
4
Operator Meaning
&&
Logical AND
||
Logical OR
!
Logical NOT
AND OR NOT
X Y X || Y
False False False
False True True
True False True
True True True
X Y X && Y
False False False
False True False
True False False
True True True
X !X
False True
True False
Logical Data and Operators
Presented By Mr.Y N D Aravind
5
Evaluating Logical Expressions
There are two methods to evaluate binary logical relations. First, expression
must be completely evaluated before the result is determined. Second, sets
the result as soon as it is known.
If the first operand of the logical and expression is false then there is no
need to evaluate the second half of the expression. And in the case of
logical or if the first operand is true then there is no need to evaluate the
second half of the expression. This is known as short circuit evaluation.
False && Anything True || Anything
FALSE TRUE
Program to illustrate about logical operators
#include<stdio.h>
#include<stdbool.h>
int main()
{
bool a = true;
bool b = false;
printf(“%d”, a&&b);
printf(“%d”, a||b);
printf(“%d”, !a&&b);
printf(“%d”, a&&!b);
printf(“%d”, !a||b);
printf(“%d”, a||!b);
return 0;
}
Presented By Mr.Y N D Aravind
6
OUTPUT
010101
In addition to logical operators, C provides six comparative operators. They all are
binary operators. They take two operands and compare to produce Boolean
value.(true or false). They are divided into two groups.
1. Relational operators 2. Equality operators
The relational and equality operators
are listed below:
Operator Meaning
< Is less than
<= Is less than or equal to
> Is Greater than
>= Is Greater than or
equal to
== Is Equalto
!= Is Not Equal to
Comparative Operators
Presented By Mr.Y N D Aravind
7
For example, x>y, x<y, x==y,
x>=y, x<=y, x!=y
Operator Complement
< >=
> <=
== !=
Comparative Operators
If we want to simplify an expression containing not less than operators,
we use greater than or equal to operator.
Presented By Mr.Y N D Aravind
8
Original expression Simplified expression
!(x < y) x >= y
!(x > y) x <= y
!(x != y) x == y
!(x <= y) x > y
!(x >= y) x < y
!(x == y) x != y
CONDITIONAL STATEMENT
Decision making is about deciding the order of execution of statements based on
certain conditions or repeat a group of statements until certain specified
conditions are met. C language handles decision-making by supporting the
following statements,
1. If statement
2. Switch statement
3. Conditional operator statement
4. Go to statement
if Statement
The if statement is powerful decision making statement and is used to control the
flow of execution of statements. The if statement may be complexity of
conditions to be tested.
1. Simple if statement
2. If else statement
3. Nested If-else statement
4. Else –If ladder statement
Presented By Mr.Y N D Aravind
9
Simple – If Statement
Syntax :-
if (test expression)
{
Statement block;
}
Statement - x ;
SINGLE WAY SELECTION
Presented By Mr.Y N D Aravind
10
Flow Chart
The statement block may be a single statement or a group of statements. If the
test expression is true then the statement block will be executed.
Otherwise the statement block will be skipped and the execution will jump to
the statement –x. If the condition is true both the statement - block and statement-x
in sequence are executed.
Example Program
if(category = sports)
{
marks = marks + bonus marks;
}
printf(“%d”, marks);
 If the student belongs to the
sports category then additional
bonus marks are added to his
marks before they are printed.
For others bonus marks are not
added.
#include<stdio.h>
Void main()
{
int x;
clrscr();
printf(“enter the value of x”);
scanf(“%d”, &x);
if (x == 1)
printf(“ x value is one”);
printf(“%d”, x);
}
Simple – If Statement
Presented By Mr.Y N D Aravind
11
If – else Statement
Syntax :-
if (test expression)
{
True block - 1;
}
Else
{
False block – 2;
}
Statement - x ;
TWO WAY SELECTION
Presented By Mr.Y N D Aravind
12
Points to note
 The expression must be enclosed in
parenthesis.
 No semicolon is required for if else
statement
 Both true and false block may
contain null statement or another if
else statement
 Both blocks may contain either one
statement or group of statements if
group then they should be presented
between a pair of braces called
compound statement.
Example Program
If (code == 1)
boy = boy + 1;
else
girl = girl + 1;
st-x;
 Here if the code is equal to „1‟ the statement
boy=boy+1; is executed and the control is
transferred to the statement st-x, after
skipping the else part. If code is not equal to
„1‟ the statement boy =boy+1; is skipped
and the statement in the else part girl
=girl+1; is executed before the control
reaches the statement st-x.
#include<stdio.h>
#include<conio.h>
Void main()
{
int num;
clrscr();
printf(“enter the value “);
scanf(„%d”, &num);
if(num%2==0)
printf(“the number is even”);
else
printf(“the number is odd”);
}
If - else Statement
Presented By Mr.Y N D Aravind
13
If – else Statement
TWO WAY SELECTION
Presented By Mr.Y N D Aravind
14
Points to note
 The expression is a C
expression. After its evaluation
its value is either true or false.
 If the test expression is true
then true-block statements are
executed, otherwise the false–
block statements are executed.
 In both cases either true-block
or false-block will be executed
but not both.
Flow Chart
Nested If – else Statement
Syntax :-
if(test expression1)
{
if(test expression2)
{ statement block –1;
}
else
{ statement block – 2;
}
}
else
{ statement block – 3;
}
Statement – x;
TWO WAY SELECTION
Presented By Mr.Y N D Aravind
15
Test
expression
St- 1 St-3St- 2
Test
expression
St -x
Flow Chart
When a series of decisions are involved we may have to use
more than one if-else statement in nested form. An if-else is
included in another if-else is known as nested if else statement.
Example Program
if(sex ==female)
{
if(balance>5000)
{
bonus=0.5*balance;
else
bonus=0.2*balance;
}
}
else
{
bonus=0.6*balance;
}
balance=balance+bonus;
printf(“%f”, balance);
#include<stdio.h>
Void main()
{
int a, b, c;
printf(“enter the values of a, b, c”);
scanf(“%d%d%d”, &a, &b, &c);
if(a>b)
{
if(a>c)
printf(“%d a is big”, a);
else
printf(“%d c is big”, c);
}
else
if(c>b)
printf(“%d c is big”, c);
else
printf(“%d b is big”, b);
}
Nested If - else Statement
Presented By Mr.Y N D Aravind
16
Dangling else problem
In nested if-else we have a problem known as dangling else problem. This problem
is created when there is no matching else for every if. In C, we have the simple
solution. “always pair an else to most recent unpaired if in the current
block”.
But however it may lead to problems hence the solution is to simplify if statements by putting braces.
if(test expression1)
{
if(test expression2)
st –1;
}
else
st – 2;
st – x;
Presented By Mr.Y N D Aravind
17
else - if ladder
Syntax :-
if (condition1)
St block–1;
else if (condition2)
St block –2;
else if (condition 3)
St block –3;
else
St block -4;
St –x;
MULTI WAY SELECTION
Presented By Mr.Y N D Aravind
18
A multi path decision is chain of if’s in which the
statement associated with each else is an if.
Flow Chart
Example Program
if (code = = 1)
Color = “red”;
else if ( code = = 2)
Color = “green”
else if (code = = 3)
Color = “white”;
else
Color = “yellow”
 If code number is other than 1, 2 and 3
then color is yellow.
#include<stdio.h>
Void main()
{ int m1,m2,m3,m4,m5, total; float per;
printf(“enter the marks for five subjects”);
scanf(“%d%d%d%d%d”, &m1, &m2, &m3, &m4, &m5);
total = m1 + m2 + m3 + m4 + m5;
per = total / 500;
printf(“%f”, per);
if(per >= 90)
printf(“A”);
else if(per >= 80)
printf(“B”);
else if(per >= 70)
printf(“C”);
else if(per >= 60)
printf(“D”);
else
printf(“F”);
}

else - if ladder
Presented By Mr.Y N D Aravind
19
Switch Statement
Syntax :-
switch (expression)
{
case value1 : block1;
break;
case value 2 : block 2;
break;
default : default block;
break;
}
st – x;
MULTI WAY SELECTION
Presented By Mr.Y N D Aravind
20
Instead of else – if ladder, ‘C’ has a built-in multi-
way decision statement known as a switch.
Flow Chart
Switch
(Expression)
Block 1 Block 2 Default
St - x
Program Program Cont
main()
{
int a , b , choice;
float c;
clrscr();
printf(“enter the values of a & b”);
scanf(“%d%d”, &a, &b);
printf(“enter the choice”);
scanf(“%d”, &choice);
switch(choice)
{
case „1‟ : c=a+b;
printf(“%f”, c);
break;
case „2‟ : c=a-b;
printf(“%f”, c);
break;
case „3‟ : c=a/b;
printf(“%f”, c);
break;
case „4‟ : c=a*b;
printf(“%f”, c);
break;
case „5‟ : c=a%b;
printf(“%f”, c);
break;
default case : printf(“Invalid option”);
break;
} getch();
}
Switch Statement
Presented By Mr.Y N D Aravind
21
Y. N. D. ARAVIND
ASSOCIATE PROFESSOR, DEPT OF CSE
N E W T O N ’ S G R O U P O F I N S T I T U T I O N S , M A C H E R L A
Presented By Mr.Y N D Aravind
22
Thank YouThank You

Más contenido relacionado

La actualidad más candente

Python If Else | If Else Statement In Python | Edureka
Python If Else | If Else Statement In Python | EdurekaPython If Else | If Else Statement In Python | Edureka
Python If Else | If Else Statement In Python | EdurekaEdureka!
 
C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorialsMayank Jain
 
If statements in c programming
If statements in c programmingIf statements in c programming
If statements in c programmingArchana Gopinath
 
Pointers and call by value, reference, address in C
Pointers and call by value, reference, address in CPointers and call by value, reference, address in C
Pointers and call by value, reference, address in CSyed Mustafa
 
Decision making and branching in c programming
Decision making and branching in c programmingDecision making and branching in c programming
Decision making and branching in c programmingPriyansh Thakar
 
Type casting in java
Type casting in javaType casting in java
Type casting in javaFarooq Baloch
 
Tokens expressionsin C++
Tokens expressionsin C++Tokens expressionsin C++
Tokens expressionsin C++HalaiHansaika
 
Asymptotic Notations
Asymptotic NotationsAsymptotic Notations
Asymptotic NotationsRishabh Soni
 
Decision Making Statement in C ppt
Decision Making Statement in C pptDecision Making Statement in C ppt
Decision Making Statement in C pptMANJUTRIPATHI7
 
array of object pointer in c++
array of object pointer in c++array of object pointer in c++
array of object pointer in c++Arpita Patel
 
RECURSION IN C
RECURSION IN C RECURSION IN C
RECURSION IN C v_jk
 

La actualidad más candente (20)

File in C language
File in C languageFile in C language
File in C language
 
Python If Else | If Else Statement In Python | Edureka
Python If Else | If Else Statement In Python | EdurekaPython If Else | If Else Statement In Python | Edureka
Python If Else | If Else Statement In Python | Edureka
 
Functions in c
Functions in cFunctions in c
Functions in c
 
C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorials
 
If statements in c programming
If statements in c programmingIf statements in c programming
If statements in c programming
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
 
Pointers and call by value, reference, address in C
Pointers and call by value, reference, address in CPointers and call by value, reference, address in C
Pointers and call by value, reference, address in C
 
Strings
StringsStrings
Strings
 
Decision making and branching in c programming
Decision making and branching in c programmingDecision making and branching in c programming
Decision making and branching in c programming
 
Type casting in java
Type casting in javaType casting in java
Type casting in java
 
Tokens expressionsin C++
Tokens expressionsin C++Tokens expressionsin C++
Tokens expressionsin C++
 
Control statements in c
Control statements in cControl statements in c
Control statements in c
 
Looping in C
Looping in CLooping in C
Looping in C
 
Asymptotic Notations
Asymptotic NotationsAsymptotic Notations
Asymptotic Notations
 
stack & queue
stack & queuestack & queue
stack & queue
 
Decision Making Statement in C ppt
Decision Making Statement in C pptDecision Making Statement in C ppt
Decision Making Statement in C ppt
 
Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++
 
Function overloading
Function overloadingFunction overloading
Function overloading
 
array of object pointer in c++
array of object pointer in c++array of object pointer in c++
array of object pointer in c++
 
RECURSION IN C
RECURSION IN C RECURSION IN C
RECURSION IN C
 

Similar a Selection & Making Decisions in c

unit 2-Control Structures.pptx
unit 2-Control Structures.pptxunit 2-Control Structures.pptx
unit 2-Control Structures.pptxishaparte4
 
Conditional statements
Conditional statementsConditional statements
Conditional statementsNabishaAK
 
Programming Fundamentals Decisions
Programming Fundamentals  Decisions Programming Fundamentals  Decisions
Programming Fundamentals Decisions imtiazalijoono
 
Unit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in CUnit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in CSowmya Jyothi
 
CONTROLSTRUCTURES.ppt
CONTROLSTRUCTURES.pptCONTROLSTRUCTURES.ppt
CONTROLSTRUCTURES.pptSanjjaayyy
 
Simple if else statement,nesting of if else statement &amp; else if ladder
Simple if else statement,nesting of if else statement &amp; else if ladderSimple if else statement,nesting of if else statement &amp; else if ladder
Simple if else statement,nesting of if else statement &amp; else if ladderMoni Adhikary
 
18CSS101J PROGRAMMING FOR PROBLEM SOLVING
18CSS101J PROGRAMMING FOR PROBLEM SOLVING18CSS101J PROGRAMMING FOR PROBLEM SOLVING
18CSS101J PROGRAMMING FOR PROBLEM SOLVINGGOWSIKRAJAP
 
Csci101 lect04 advanced_selection
Csci101 lect04 advanced_selectionCsci101 lect04 advanced_selection
Csci101 lect04 advanced_selectionElsayed Hemayed
 
Branching statements
Branching statementsBranching statements
Branching statementsArunMK17
 
Decisions in C or If condition
Decisions in C or If conditionDecisions in C or If condition
Decisions in C or If conditionyarkhosh
 
C Programming: Control Structure
C Programming: Control StructureC Programming: Control Structure
C Programming: Control StructureSokngim Sa
 

Similar a Selection & Making Decisions in c (20)

Decision Making and Branching
Decision Making and BranchingDecision Making and Branching
Decision Making and Branching
 
unit 2-Control Structures.pptx
unit 2-Control Structures.pptxunit 2-Control Structures.pptx
unit 2-Control Structures.pptx
 
Conditional statements
Conditional statementsConditional statements
Conditional statements
 
ICP - Lecture 7 and 8
ICP - Lecture 7 and 8ICP - Lecture 7 and 8
ICP - Lecture 7 and 8
 
C tutorial
C tutorialC tutorial
C tutorial
 
175035 cse lab-03
175035 cse lab-03175035 cse lab-03
175035 cse lab-03
 
Programming Fundamentals Decisions
Programming Fundamentals  Decisions Programming Fundamentals  Decisions
Programming Fundamentals Decisions
 
Unit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in CUnit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in C
 
CONTROLSTRUCTURES.ppt
CONTROLSTRUCTURES.pptCONTROLSTRUCTURES.ppt
CONTROLSTRUCTURES.ppt
 
Control statments in c
Control statments in cControl statments in c
Control statments in c
 
Simple if else statement,nesting of if else statement &amp; else if ladder
Simple if else statement,nesting of if else statement &amp; else if ladderSimple if else statement,nesting of if else statement &amp; else if ladder
Simple if else statement,nesting of if else statement &amp; else if ladder
 
18CSS101J PROGRAMMING FOR PROBLEM SOLVING
18CSS101J PROGRAMMING FOR PROBLEM SOLVING18CSS101J PROGRAMMING FOR PROBLEM SOLVING
18CSS101J PROGRAMMING FOR PROBLEM SOLVING
 
Csci101 lect04 advanced_selection
Csci101 lect04 advanced_selectionCsci101 lect04 advanced_selection
Csci101 lect04 advanced_selection
 
C fundamental
C fundamentalC fundamental
C fundamental
 
L3 control
L3 controlL3 control
L3 control
 
Branching statements
Branching statementsBranching statements
Branching statements
 
Decisions in C or If condition
Decisions in C or If conditionDecisions in C or If condition
Decisions in C or If condition
 
Programming for Problem Solving
Programming for Problem SolvingProgramming for Problem Solving
Programming for Problem Solving
 
C Programming: Control Structure
C Programming: Control StructureC Programming: Control Structure
C Programming: Control Structure
 
CH-4 (1).pptx
CH-4 (1).pptxCH-4 (1).pptx
CH-4 (1).pptx
 

Más de yndaravind

Más de yndaravind (14)

Introduction to UML
Introduction to UMLIntroduction to UML
Introduction to UML
 
Classes and Objects
Classes and Objects  Classes and Objects
Classes and Objects
 
The Object Model
The Object Model  The Object Model
The Object Model
 
OOAD
OOADOOAD
OOAD
 
OOAD
OOADOOAD
OOAD
 
FILES IN C
FILES IN CFILES IN C
FILES IN C
 
Repetations in C
Repetations in CRepetations in C
Repetations in C
 
Bitwise Operators in C
Bitwise Operators in CBitwise Operators in C
Bitwise Operators in C
 
Structure In C
Structure In CStructure In C
Structure In C
 
Strings part2
Strings part2Strings part2
Strings part2
 
Arrays In C
Arrays In CArrays In C
Arrays In C
 
Strings IN C
Strings IN CStrings IN C
Strings IN C
 
Fnctions part2
Fnctions part2Fnctions part2
Fnctions part2
 
Functions part1
Functions part1Functions part1
Functions part1
 

Último

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.pdfAdmir Softic
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024Janet Corral
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 

Último (20)

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
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 

Selection & Making Decisions in c

  • 1. B Y Y N D ARAVIND A S S O C I A T E P R O F E S S O R , D E P T O F C S E N E W T O N ’ S G R O U P O F I N S T I T U T I O N S , M A C H E R L A @2020 Presented By Mr.Y N D Aravind 1 SELECTION – MAKING DECISIONS
  • 2. P A R T - I I L O G I C A L D A T A A N D O P E R A T O R S T W O W A Y S E L E C T I O N M U L T I W A Y S E L E C T I O N M O R E S T A N D A R D F U N C T I O N S @2020 Presented By Mr.Y N D Aravind 2 SELECTION – MAKING DECISIONS
  • 3. Logical Data and Operators Presented By Mr.Y N D Aravind 3 A piece of data is called logical if it gives information as true or false. For this, we have boolean data type called _bool, declared as unsigned integer in stdbool.h file. To support logical data we have to use bool type. Logical operators are used to combine two or more relations. The logical operators are called Boolean operators. Because the test between values are reduced to either true or false, with zero being false and one being true.
  • 4. Logical Data and Operators Presented By Mr.Y N D Aravind 4 Operator Meaning && Logical AND || Logical OR ! Logical NOT AND OR NOT X Y X || Y False False False False True True True False True True True True X Y X && Y False False False False True False True False False True True True X !X False True True False
  • 5. Logical Data and Operators Presented By Mr.Y N D Aravind 5 Evaluating Logical Expressions There are two methods to evaluate binary logical relations. First, expression must be completely evaluated before the result is determined. Second, sets the result as soon as it is known. If the first operand of the logical and expression is false then there is no need to evaluate the second half of the expression. And in the case of logical or if the first operand is true then there is no need to evaluate the second half of the expression. This is known as short circuit evaluation. False && Anything True || Anything FALSE TRUE
  • 6. Program to illustrate about logical operators #include<stdio.h> #include<stdbool.h> int main() { bool a = true; bool b = false; printf(“%d”, a&&b); printf(“%d”, a||b); printf(“%d”, !a&&b); printf(“%d”, a&&!b); printf(“%d”, !a||b); printf(“%d”, a||!b); return 0; } Presented By Mr.Y N D Aravind 6 OUTPUT 010101
  • 7. In addition to logical operators, C provides six comparative operators. They all are binary operators. They take two operands and compare to produce Boolean value.(true or false). They are divided into two groups. 1. Relational operators 2. Equality operators The relational and equality operators are listed below: Operator Meaning < Is less than <= Is less than or equal to > Is Greater than >= Is Greater than or equal to == Is Equalto != Is Not Equal to Comparative Operators Presented By Mr.Y N D Aravind 7 For example, x>y, x<y, x==y, x>=y, x<=y, x!=y Operator Complement < >= > <= == !=
  • 8. Comparative Operators If we want to simplify an expression containing not less than operators, we use greater than or equal to operator. Presented By Mr.Y N D Aravind 8 Original expression Simplified expression !(x < y) x >= y !(x > y) x <= y !(x != y) x == y !(x <= y) x > y !(x >= y) x < y !(x == y) x != y
  • 9. CONDITIONAL STATEMENT Decision making is about deciding the order of execution of statements based on certain conditions or repeat a group of statements until certain specified conditions are met. C language handles decision-making by supporting the following statements, 1. If statement 2. Switch statement 3. Conditional operator statement 4. Go to statement if Statement The if statement is powerful decision making statement and is used to control the flow of execution of statements. The if statement may be complexity of conditions to be tested. 1. Simple if statement 2. If else statement 3. Nested If-else statement 4. Else –If ladder statement Presented By Mr.Y N D Aravind 9
  • 10. Simple – If Statement Syntax :- if (test expression) { Statement block; } Statement - x ; SINGLE WAY SELECTION Presented By Mr.Y N D Aravind 10 Flow Chart The statement block may be a single statement or a group of statements. If the test expression is true then the statement block will be executed. Otherwise the statement block will be skipped and the execution will jump to the statement –x. If the condition is true both the statement - block and statement-x in sequence are executed.
  • 11. Example Program if(category = sports) { marks = marks + bonus marks; } printf(“%d”, marks);  If the student belongs to the sports category then additional bonus marks are added to his marks before they are printed. For others bonus marks are not added. #include<stdio.h> Void main() { int x; clrscr(); printf(“enter the value of x”); scanf(“%d”, &x); if (x == 1) printf(“ x value is one”); printf(“%d”, x); } Simple – If Statement Presented By Mr.Y N D Aravind 11
  • 12. If – else Statement Syntax :- if (test expression) { True block - 1; } Else { False block – 2; } Statement - x ; TWO WAY SELECTION Presented By Mr.Y N D Aravind 12 Points to note  The expression must be enclosed in parenthesis.  No semicolon is required for if else statement  Both true and false block may contain null statement or another if else statement  Both blocks may contain either one statement or group of statements if group then they should be presented between a pair of braces called compound statement.
  • 13. Example Program If (code == 1) boy = boy + 1; else girl = girl + 1; st-x;  Here if the code is equal to „1‟ the statement boy=boy+1; is executed and the control is transferred to the statement st-x, after skipping the else part. If code is not equal to „1‟ the statement boy =boy+1; is skipped and the statement in the else part girl =girl+1; is executed before the control reaches the statement st-x. #include<stdio.h> #include<conio.h> Void main() { int num; clrscr(); printf(“enter the value “); scanf(„%d”, &num); if(num%2==0) printf(“the number is even”); else printf(“the number is odd”); } If - else Statement Presented By Mr.Y N D Aravind 13
  • 14. If – else Statement TWO WAY SELECTION Presented By Mr.Y N D Aravind 14 Points to note  The expression is a C expression. After its evaluation its value is either true or false.  If the test expression is true then true-block statements are executed, otherwise the false– block statements are executed.  In both cases either true-block or false-block will be executed but not both. Flow Chart
  • 15. Nested If – else Statement Syntax :- if(test expression1) { if(test expression2) { statement block –1; } else { statement block – 2; } } else { statement block – 3; } Statement – x; TWO WAY SELECTION Presented By Mr.Y N D Aravind 15 Test expression St- 1 St-3St- 2 Test expression St -x Flow Chart When a series of decisions are involved we may have to use more than one if-else statement in nested form. An if-else is included in another if-else is known as nested if else statement.
  • 16. Example Program if(sex ==female) { if(balance>5000) { bonus=0.5*balance; else bonus=0.2*balance; } } else { bonus=0.6*balance; } balance=balance+bonus; printf(“%f”, balance); #include<stdio.h> Void main() { int a, b, c; printf(“enter the values of a, b, c”); scanf(“%d%d%d”, &a, &b, &c); if(a>b) { if(a>c) printf(“%d a is big”, a); else printf(“%d c is big”, c); } else if(c>b) printf(“%d c is big”, c); else printf(“%d b is big”, b); } Nested If - else Statement Presented By Mr.Y N D Aravind 16
  • 17. Dangling else problem In nested if-else we have a problem known as dangling else problem. This problem is created when there is no matching else for every if. In C, we have the simple solution. “always pair an else to most recent unpaired if in the current block”. But however it may lead to problems hence the solution is to simplify if statements by putting braces. if(test expression1) { if(test expression2) st –1; } else st – 2; st – x; Presented By Mr.Y N D Aravind 17
  • 18. else - if ladder Syntax :- if (condition1) St block–1; else if (condition2) St block –2; else if (condition 3) St block –3; else St block -4; St –x; MULTI WAY SELECTION Presented By Mr.Y N D Aravind 18 A multi path decision is chain of if’s in which the statement associated with each else is an if. Flow Chart
  • 19. Example Program if (code = = 1) Color = “red”; else if ( code = = 2) Color = “green” else if (code = = 3) Color = “white”; else Color = “yellow”  If code number is other than 1, 2 and 3 then color is yellow. #include<stdio.h> Void main() { int m1,m2,m3,m4,m5, total; float per; printf(“enter the marks for five subjects”); scanf(“%d%d%d%d%d”, &m1, &m2, &m3, &m4, &m5); total = m1 + m2 + m3 + m4 + m5; per = total / 500; printf(“%f”, per); if(per >= 90) printf(“A”); else if(per >= 80) printf(“B”); else if(per >= 70) printf(“C”); else if(per >= 60) printf(“D”); else printf(“F”); }  else - if ladder Presented By Mr.Y N D Aravind 19
  • 20. Switch Statement Syntax :- switch (expression) { case value1 : block1; break; case value 2 : block 2; break; default : default block; break; } st – x; MULTI WAY SELECTION Presented By Mr.Y N D Aravind 20 Instead of else – if ladder, ‘C’ has a built-in multi- way decision statement known as a switch. Flow Chart Switch (Expression) Block 1 Block 2 Default St - x
  • 21. Program Program Cont main() { int a , b , choice; float c; clrscr(); printf(“enter the values of a & b”); scanf(“%d%d”, &a, &b); printf(“enter the choice”); scanf(“%d”, &choice); switch(choice) { case „1‟ : c=a+b; printf(“%f”, c); break; case „2‟ : c=a-b; printf(“%f”, c); break; case „3‟ : c=a/b; printf(“%f”, c); break; case „4‟ : c=a*b; printf(“%f”, c); break; case „5‟ : c=a%b; printf(“%f”, c); break; default case : printf(“Invalid option”); break; } getch(); } Switch Statement Presented By Mr.Y N D Aravind 21
  • 22. Y. N. D. ARAVIND ASSOCIATE PROFESSOR, DEPT OF CSE N E W T O N ’ S G R O U P O F I N S T I T U T I O N S , M A C H E R L A Presented By Mr.Y N D Aravind 22 Thank YouThank You