SlideShare a Scribd company logo
PROGRAMMING
IF STATEMENTS &
RELATIONAL
OPERATORS
By: John Paul Espino
De La Salle University – Dasmarinas
Facebook.com/Johnpaul.dss
Computer Programming - if Statements  & Relational Operators
CONDITIONAL STATEMENTS
• A conditional statement allows us to control whether a program segment is executed or not.
• Two constructs
• if statement
• if
• if-else
• if-else-if
• switch statement
THE BASIC IF STATEMENT
• Syntax
if(condition)
action
• if the condition is true then
execute the action.
• action is either a single
statement or a group of
statements within braces.
condition
action
true
false
CHOICE (IF)
 Put multiple action statements
within braces
if (it's raining){
printf(“take umbrella”);
printf(“wear raincoat”);
}
ABSOLUTE VALUE
// program to read number & print its absolute value
#include <stdio.h>
main(){
int value;
printf("Enter integer: “);
scanf(“%d”,&value);
if(value < 0)
value = -value;
printf("The absolute value is %d “,value);
getch();
}
RELATIONAL OPERATORS
Relational operators are used to compare two values to form a
condition.
Math C Plain English
= == equals [example: if(a==b) ]
[ (a=b) means put the value of b into a ]
< < less than
 <= less than or equal to
> > greater than
 >= greater than or equal to
 != not equal to
CONDITIONS
Examples:
Number_of_Students < 200
10 > 20
20 * j == 10 + i
THE BOOLEAN TYPE
• C contains a type named bool for conditions.
• A condition can have one of two values:
• true (corresponds to a non-zero value)
• false (corresponds to zero value)
• Boolean operators can be used to form more complex conditional
expressions.
• The and operator is &&
• The or operator is ||
• The not operator is !
THE BOOLEAN TYPE
• Truth table for "&&" (AND):
Operand1 Operand2 Operand1 &&
Operand2
true true true
true false false
false true false
false false false
THE BOOLEAN TYPE
• Truth table for “||" (OR):
Operand1 Operand2 Operand1 ||
Operand2
true true true
true false true
false true true
false false false
THE BOOLEAN TYPE
• Truth table for "!" (NOT):
Operand !Operand
true false
false true
A BOOLEAN TYPE
• Assignments to bool type variables
bool P = true;
bool Q = false;
bool R = true;
bool S = P && Q;
bool T = !Q || R;
bool U = !(R && !Q);
“IF” WITH A BLOCK OF STATEMENTS
if (aValue <= 10)
{
printf("Answer is %.2fn", aValue);
countB++;
}
POSITIVE OR NEGATIVE
#include <stdio.h>
main()
{
int number;
clrscr();
printf(“Enter a number”);
scanf(“%d”,&number);
if (number>0)
printf(“It is Positive”);
getch();
}
IF-ELSE STATEMENT
SYNTAX OF IF-ELSE STATEMENT
if ( condition)
statement;
else
statement;
IF – ELSE WITH A BLOCK OF STATEMENTS
if (aValue <= 10)
{
printf("Answer is %.2fn", aValue);
countB++;
} End if
else
{
printf("Error occurredn");
countC++;
} End else
TO VOTE OR NOT TO VOTE
#include<stdio.h>
main()
{
int age;
clrscr();
printf(“Enter your age”);
scanf(“%d”,&age);
if (age>=18)
printf(“You are qualified to vote”);
else
printf(“Not qualified to vote”);
getch();
}
POSITIVE OR NEGATIVE
#include <stdio.h>
main()
{
int number;
clrscr();
printf(“Enter a number”);
scanf(“%d”,&number);
if (number>0)
printf(“Positive number”);
else
printf(“Negative number”);
getch();
}
Ad

Recommended

operators and control statements in c language
operators and control statements in c language
shhanks
 
Control statements in c
Control statements in c
Sathish Narayanan
 
Types of c operators ppt
Types of c operators ppt
Viraj Shah
 
Control statements and functions in c
Control statements and functions in c
vampugani
 
Control Flow Statements
Control Flow Statements
Tarun Sharma
 
9. statements (conditional statements)
9. statements (conditional statements)
Way2itech
 
Control statement in c
Control statement in c
baabtra.com - No. 1 supplier of quality freshers
 
Decision Control Structure If & Else
Decision Control Structure If & Else
Abdullah Bhojani
 
The Three Basic Selection Structures in C++ Programming Concepts
The Three Basic Selection Structures in C++ Programming Concepts
Tech
 
Decision making and branching
Decision making and branching
Hossain Md Shakhawat
 
Control structures in C
Control structures in C
baabtra.com - No. 1 supplier of quality freshers
 
Decision Making Statement in C ppt
Decision Making Statement in C ppt
MANJUTRIPATHI7
 
Control structures in c
Control structures in c
baabtra.com - No. 1 supplier of quality freshers
 
Logical and Conditional Operator In C language
Logical and Conditional Operator In C language
Abdul Rehman
 
Selection Statements in C Programming
Selection Statements in C Programming
Kamal Acharya
 
C programming decision making
C programming decision making
SENA
 
Control structure in c
Control structure in c
baabtra.com - No. 1 supplier of quality freshers
 
C lecture 3 control statements slideshare
C lecture 3 control statements slideshare
Gagan Deep
 
Control and conditional statements
Control and conditional statements
rajshreemuthiah
 
Decision making statements in C programming
Decision making statements in C programming
Rabin BK
 
C Programming: Control Structure
C Programming: Control Structure
Sokngim Sa
 
Control structure C++
Control structure C++
Anil Kumar
 
Visula C# Programming Lecture 3
Visula C# Programming Lecture 3
Abou Bakr Ashraf
 
Control structure of c
Control structure of c
Komal Kotak
 
Conditional operators
Conditional operators
BU
 
Control Structures
Control Structures
Ghaffar Khan
 
Unit 5. Control Statement
Unit 5. Control Statement
Ashim Lamichhane
 
Mesics lecture 6 control statement = if -else if__else
Mesics lecture 6 control statement = if -else if__else
eShikshak
 
C statements (a fraction).pptx
C statements (a fraction).pptx
MehrinFarjana
 
If
If
Priya Doke
 

More Related Content

What's hot (20)

The Three Basic Selection Structures in C++ Programming Concepts
The Three Basic Selection Structures in C++ Programming Concepts
Tech
 
Decision making and branching
Decision making and branching
Hossain Md Shakhawat
 
Control structures in C
Control structures in C
baabtra.com - No. 1 supplier of quality freshers
 
Decision Making Statement in C ppt
Decision Making Statement in C ppt
MANJUTRIPATHI7
 
Control structures in c
Control structures in c
baabtra.com - No. 1 supplier of quality freshers
 
Logical and Conditional Operator In C language
Logical and Conditional Operator In C language
Abdul Rehman
 
Selection Statements in C Programming
Selection Statements in C Programming
Kamal Acharya
 
C programming decision making
C programming decision making
SENA
 
Control structure in c
Control structure in c
baabtra.com - No. 1 supplier of quality freshers
 
C lecture 3 control statements slideshare
C lecture 3 control statements slideshare
Gagan Deep
 
Control and conditional statements
Control and conditional statements
rajshreemuthiah
 
Decision making statements in C programming
Decision making statements in C programming
Rabin BK
 
C Programming: Control Structure
C Programming: Control Structure
Sokngim Sa
 
Control structure C++
Control structure C++
Anil Kumar
 
Visula C# Programming Lecture 3
Visula C# Programming Lecture 3
Abou Bakr Ashraf
 
Control structure of c
Control structure of c
Komal Kotak
 
Conditional operators
Conditional operators
BU
 
Control Structures
Control Structures
Ghaffar Khan
 
Unit 5. Control Statement
Unit 5. Control Statement
Ashim Lamichhane
 
Mesics lecture 6 control statement = if -else if__else
Mesics lecture 6 control statement = if -else if__else
eShikshak
 
The Three Basic Selection Structures in C++ Programming Concepts
The Three Basic Selection Structures in C++ Programming Concepts
Tech
 
Decision Making Statement in C ppt
Decision Making Statement in C ppt
MANJUTRIPATHI7
 
Logical and Conditional Operator In C language
Logical and Conditional Operator In C language
Abdul Rehman
 
Selection Statements in C Programming
Selection Statements in C Programming
Kamal Acharya
 
C programming decision making
C programming decision making
SENA
 
C lecture 3 control statements slideshare
C lecture 3 control statements slideshare
Gagan Deep
 
Control and conditional statements
Control and conditional statements
rajshreemuthiah
 
Decision making statements in C programming
Decision making statements in C programming
Rabin BK
 
C Programming: Control Structure
C Programming: Control Structure
Sokngim Sa
 
Control structure C++
Control structure C++
Anil Kumar
 
Visula C# Programming Lecture 3
Visula C# Programming Lecture 3
Abou Bakr Ashraf
 
Control structure of c
Control structure of c
Komal Kotak
 
Conditional operators
Conditional operators
BU
 
Control Structures
Control Structures
Ghaffar Khan
 
Mesics lecture 6 control statement = if -else if__else
Mesics lecture 6 control statement = if -else if__else
eShikshak
 

Similar to Computer Programming - if Statements & Relational Operators (20)

C statements (a fraction).pptx
C statements (a fraction).pptx
MehrinFarjana
 
If
If
Priya Doke
 
M C6java5
M C6java5
mbruggen
 
if,loop,switch
if,loop,switch
baabtra.com - No. 1 supplier of quality freshers
 
Java unit 3
Java unit 3
Shipra Swati
 
10-Lec - Nested IF Statement.pptx
10-Lec - Nested IF Statement.pptx
AqeelAbbas94
 
Control statments in c
Control statments in c
CGC Technical campus,Mohali
 
SPL 8 | Loop Statements in C
SPL 8 | Loop Statements in C
Mohammad Imam Hossain
 
Ref Lec 4- Conditional Statement (1).pptx
Ref Lec 4- Conditional Statement (1).pptx
BilalAhmad735613
 
C language UPTU Unit3 Slides
C language UPTU Unit3 Slides
Anurag University Hyderabad
 
Module 2 - Control Structures c programming.pptm.pdf
Module 2 - Control Structures c programming.pptm.pdf
SudipDebnath20
 
Bsit1
Bsit1
jigeno
 
Ap Power Point Chpt3 B
Ap Power Point Chpt3 B
dplunkett
 
ICSE Class X Conditional Statements in java
ICSE Class X Conditional Statements in java
VanitaKarthik2
 
UNIT 2 programming in java_operators.pptx
UNIT 2 programming in java_operators.pptx
jijinamt
 
Fundamental of Information Technology - UNIT 8
Fundamental of Information Technology - UNIT 8
Shipra Swati
 
Programming Fundamentals Decisions
Programming Fundamentals Decisions
imtiazalijoono
 
L05if
L05if
Kgr Sushmitha
 
Unit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in C
Sowmya Jyothi
 
Kaush, Vitali - Title: Exploring the Power of V5 Sensors in Robotics: Enhanci...
Kaush, Vitali - Title: Exploring the Power of V5 Sensors in Robotics: Enhanci...
vitalikaush1
 
C statements (a fraction).pptx
C statements (a fraction).pptx
MehrinFarjana
 
10-Lec - Nested IF Statement.pptx
10-Lec - Nested IF Statement.pptx
AqeelAbbas94
 
Ref Lec 4- Conditional Statement (1).pptx
Ref Lec 4- Conditional Statement (1).pptx
BilalAhmad735613
 
Module 2 - Control Structures c programming.pptm.pdf
Module 2 - Control Structures c programming.pptm.pdf
SudipDebnath20
 
Ap Power Point Chpt3 B
Ap Power Point Chpt3 B
dplunkett
 
ICSE Class X Conditional Statements in java
ICSE Class X Conditional Statements in java
VanitaKarthik2
 
UNIT 2 programming in java_operators.pptx
UNIT 2 programming in java_operators.pptx
jijinamt
 
Fundamental of Information Technology - UNIT 8
Fundamental of Information Technology - UNIT 8
Shipra Swati
 
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 C
Sowmya Jyothi
 
Kaush, Vitali - Title: Exploring the Power of V5 Sensors in Robotics: Enhanci...
Kaush, Vitali - Title: Exploring the Power of V5 Sensors in Robotics: Enhanci...
vitalikaush1
 
Ad

More from John Paul Espino (20)

Religion Education - Sa kabataang Pilipino - A La Juventud Filipina
Religion Education - Sa kabataang Pilipino - A La Juventud Filipina
John Paul Espino
 
Religion Education - Human Dignity - Freedom and Responsibility
Religion Education - Human Dignity - Freedom and Responsibility
John Paul Espino
 
Public Speaking and Leadership -Process of Reading
Public Speaking and Leadership -Process of Reading
John Paul Espino
 
Environmental Engineering - Case Study - The Minamata Disease Disaster
Environmental Engineering - Case Study - The Minamata Disease Disaster
John Paul Espino
 
Philippine Constitution - Parliamentary Immunity
Philippine Constitution - Parliamentary Immunity
John Paul Espino
 
Philippine Constitution - Article XI - Accountability of Public Officers
Philippine Constitution - Article XI - Accountability of Public Officers
John Paul Espino
 
Philippine Constitution - Article X - Local Government
Philippine Constitution - Article X - Local Government
John Paul Espino
 
Philippine Constitution - Article VIII - Judicial Department
Philippine Constitution - Article VIII - Judicial Department
John Paul Espino
 
Philippine Constitution - Article VII - Executive Department
Philippine Constitution - Article VII - Executive Department
John Paul Espino
 
Philippine Constitution - Article VI - Legislative Power
Philippine Constitution - Article VI - Legislative Power
John Paul Espino
 
Philippine Constitution - ARTICLE IX - Constitutional Commissions
Philippine Constitution - ARTICLE IX - Constitutional Commissions
John Paul Espino
 
Philosophy - the aesthetic attitude and the sublime
Philosophy - the aesthetic attitude and the sublime
John Paul Espino
 
Philosophy - the aestheic attidude and the sublime
Philosophy - the aestheic attidude and the sublime
John Paul Espino
 
Information literacy - effects of social networking to students thesis presen...
Information literacy - effects of social networking to students thesis presen...
John Paul Espino
 
Fundamentals of Accounting - Posting & Trial Balance
Fundamentals of Accounting - Posting & Trial Balance
John Paul Espino
 
Fundamentals of accounting - manufacturing
Fundamentals of accounting - manufacturing
John Paul Espino
 
Fundamentals of accounting - cost value profit (cvp)
Fundamentals of accounting - cost value profit (cvp)
John Paul Espino
 
Ethics - nicomachean ethics section 7 - 9
Ethics - nicomachean ethics section 7 - 9
John Paul Espino
 
Ethics - aristotle's ethics
Ethics - aristotle's ethics
John Paul Espino
 
Environmental engineering - oxygen cycle
Environmental engineering - oxygen cycle
John Paul Espino
 
Religion Education - Sa kabataang Pilipino - A La Juventud Filipina
Religion Education - Sa kabataang Pilipino - A La Juventud Filipina
John Paul Espino
 
Religion Education - Human Dignity - Freedom and Responsibility
Religion Education - Human Dignity - Freedom and Responsibility
John Paul Espino
 
Public Speaking and Leadership -Process of Reading
Public Speaking and Leadership -Process of Reading
John Paul Espino
 
Environmental Engineering - Case Study - The Minamata Disease Disaster
Environmental Engineering - Case Study - The Minamata Disease Disaster
John Paul Espino
 
Philippine Constitution - Parliamentary Immunity
Philippine Constitution - Parliamentary Immunity
John Paul Espino
 
Philippine Constitution - Article XI - Accountability of Public Officers
Philippine Constitution - Article XI - Accountability of Public Officers
John Paul Espino
 
Philippine Constitution - Article X - Local Government
Philippine Constitution - Article X - Local Government
John Paul Espino
 
Philippine Constitution - Article VIII - Judicial Department
Philippine Constitution - Article VIII - Judicial Department
John Paul Espino
 
Philippine Constitution - Article VII - Executive Department
Philippine Constitution - Article VII - Executive Department
John Paul Espino
 
Philippine Constitution - Article VI - Legislative Power
Philippine Constitution - Article VI - Legislative Power
John Paul Espino
 
Philippine Constitution - ARTICLE IX - Constitutional Commissions
Philippine Constitution - ARTICLE IX - Constitutional Commissions
John Paul Espino
 
Philosophy - the aesthetic attitude and the sublime
Philosophy - the aesthetic attitude and the sublime
John Paul Espino
 
Philosophy - the aestheic attidude and the sublime
Philosophy - the aestheic attidude and the sublime
John Paul Espino
 
Information literacy - effects of social networking to students thesis presen...
Information literacy - effects of social networking to students thesis presen...
John Paul Espino
 
Fundamentals of Accounting - Posting & Trial Balance
Fundamentals of Accounting - Posting & Trial Balance
John Paul Espino
 
Fundamentals of accounting - manufacturing
Fundamentals of accounting - manufacturing
John Paul Espino
 
Fundamentals of accounting - cost value profit (cvp)
Fundamentals of accounting - cost value profit (cvp)
John Paul Espino
 
Ethics - nicomachean ethics section 7 - 9
Ethics - nicomachean ethics section 7 - 9
John Paul Espino
 
Ethics - aristotle's ethics
Ethics - aristotle's ethics
John Paul Espino
 
Environmental engineering - oxygen cycle
Environmental engineering - oxygen cycle
John Paul Espino
 
Ad

Recently uploaded (20)

SAP PM Module Level-IV Training Complete.ppt
SAP PM Module Level-IV Training Complete.ppt
MuhammadShaheryar36
 
What is data visualization and how data visualization tool can help.pdf
What is data visualization and how data visualization tool can help.pdf
Varsha Nayak
 
Insurance Underwriting Software Enhancing Accuracy and Efficiency
Insurance Underwriting Software Enhancing Accuracy and Efficiency
Insurance Tech Services
 
Async-ronizing Success at Wix - Patterns for Seamless Microservices - Devoxx ...
Async-ronizing Success at Wix - Patterns for Seamless Microservices - Devoxx ...
Natan Silnitsky
 
Code and No-Code Journeys: The Coverage Overlook
Code and No-Code Journeys: The Coverage Overlook
Applitools
 
Porting Qt 5 QML Modules to Qt 6 Webinar
Porting Qt 5 QML Modules to Qt 6 Webinar
ICS
 
How the US Navy Approaches DevSecOps with Raise 2.0
How the US Navy Approaches DevSecOps with Raise 2.0
Anchore
 
Shell Skill Tree - LabEx Certification (LabEx)
Shell Skill Tree - LabEx Certification (LabEx)
VICTOR MAESTRE RAMIREZ
 
Looking for a BIRT Report Alternative Here’s Why Helical Insight Stands Out.pdf
Looking for a BIRT Report Alternative Here’s Why Helical Insight Stands Out.pdf
Varsha Nayak
 
Enable Your Cloud Journey With Microsoft Trusted Partner | IFI Tech
Enable Your Cloud Journey With Microsoft Trusted Partner | IFI Tech
IFI Techsolutions
 
Who will create the languages of the future?
Who will create the languages of the future?
Jordi Cabot
 
Step by step guide to install Flutter and Dart
Step by step guide to install Flutter and Dart
S Pranav (Deepu)
 
Migrating to Azure Cosmos DB the Right Way
Migrating to Azure Cosmos DB the Right Way
Alexander (Alex) Komyagin
 
What is data visualization and how data visualization tool can help.pptx
What is data visualization and how data visualization tool can help.pptx
Varsha Nayak
 
SAP Datasphere Catalog L2 (2024-02-07).pptx
SAP Datasphere Catalog L2 (2024-02-07).pptx
HimanshuSachdeva46
 
Advanced Token Development - Decentralized Innovation
Advanced Token Development - Decentralized Innovation
arohisinghas720
 
Application Modernization with Choreo - The AI-Native Internal Developer Plat...
Application Modernization with Choreo - The AI-Native Internal Developer Plat...
WSO2
 
Integrating Survey123 and R&H Data Using FME
Integrating Survey123 and R&H Data Using FME
Safe Software
 
Smadav Pro 2025 Rev 15.4 Crack Full Version With Registration Key
Smadav Pro 2025 Rev 15.4 Crack Full Version With Registration Key
joybepari360
 
MOVIE RECOMMENDATION SYSTEM, UDUMULA GOPI REDDY, Y24MC13085.pptx
MOVIE RECOMMENDATION SYSTEM, UDUMULA GOPI REDDY, Y24MC13085.pptx
Maharshi Mallela
 
SAP PM Module Level-IV Training Complete.ppt
SAP PM Module Level-IV Training Complete.ppt
MuhammadShaheryar36
 
What is data visualization and how data visualization tool can help.pdf
What is data visualization and how data visualization tool can help.pdf
Varsha Nayak
 
Insurance Underwriting Software Enhancing Accuracy and Efficiency
Insurance Underwriting Software Enhancing Accuracy and Efficiency
Insurance Tech Services
 
Async-ronizing Success at Wix - Patterns for Seamless Microservices - Devoxx ...
Async-ronizing Success at Wix - Patterns for Seamless Microservices - Devoxx ...
Natan Silnitsky
 
Code and No-Code Journeys: The Coverage Overlook
Code and No-Code Journeys: The Coverage Overlook
Applitools
 
Porting Qt 5 QML Modules to Qt 6 Webinar
Porting Qt 5 QML Modules to Qt 6 Webinar
ICS
 
How the US Navy Approaches DevSecOps with Raise 2.0
How the US Navy Approaches DevSecOps with Raise 2.0
Anchore
 
Shell Skill Tree - LabEx Certification (LabEx)
Shell Skill Tree - LabEx Certification (LabEx)
VICTOR MAESTRE RAMIREZ
 
Looking for a BIRT Report Alternative Here’s Why Helical Insight Stands Out.pdf
Looking for a BIRT Report Alternative Here’s Why Helical Insight Stands Out.pdf
Varsha Nayak
 
Enable Your Cloud Journey With Microsoft Trusted Partner | IFI Tech
Enable Your Cloud Journey With Microsoft Trusted Partner | IFI Tech
IFI Techsolutions
 
Who will create the languages of the future?
Who will create the languages of the future?
Jordi Cabot
 
Step by step guide to install Flutter and Dart
Step by step guide to install Flutter and Dart
S Pranav (Deepu)
 
What is data visualization and how data visualization tool can help.pptx
What is data visualization and how data visualization tool can help.pptx
Varsha Nayak
 
SAP Datasphere Catalog L2 (2024-02-07).pptx
SAP Datasphere Catalog L2 (2024-02-07).pptx
HimanshuSachdeva46
 
Advanced Token Development - Decentralized Innovation
Advanced Token Development - Decentralized Innovation
arohisinghas720
 
Application Modernization with Choreo - The AI-Native Internal Developer Plat...
Application Modernization with Choreo - The AI-Native Internal Developer Plat...
WSO2
 
Integrating Survey123 and R&H Data Using FME
Integrating Survey123 and R&H Data Using FME
Safe Software
 
Smadav Pro 2025 Rev 15.4 Crack Full Version With Registration Key
Smadav Pro 2025 Rev 15.4 Crack Full Version With Registration Key
joybepari360
 
MOVIE RECOMMENDATION SYSTEM, UDUMULA GOPI REDDY, Y24MC13085.pptx
MOVIE RECOMMENDATION SYSTEM, UDUMULA GOPI REDDY, Y24MC13085.pptx
Maharshi Mallela
 

Computer Programming - if Statements & Relational Operators

  • 1. PROGRAMMING IF STATEMENTS & RELATIONAL OPERATORS By: John Paul Espino De La Salle University – Dasmarinas Facebook.com/Johnpaul.dss
  • 3. CONDITIONAL STATEMENTS • A conditional statement allows us to control whether a program segment is executed or not. • Two constructs • if statement • if • if-else • if-else-if • switch statement
  • 4. THE BASIC IF STATEMENT • Syntax if(condition) action • if the condition is true then execute the action. • action is either a single statement or a group of statements within braces. condition action true false
  • 5. CHOICE (IF)  Put multiple action statements within braces if (it's raining){ printf(“take umbrella”); printf(“wear raincoat”); }
  • 6. ABSOLUTE VALUE // program to read number & print its absolute value #include <stdio.h> main(){ int value; printf("Enter integer: “); scanf(“%d”,&value); if(value < 0) value = -value; printf("The absolute value is %d “,value); getch(); }
  • 7. RELATIONAL OPERATORS Relational operators are used to compare two values to form a condition. Math C Plain English = == equals [example: if(a==b) ] [ (a=b) means put the value of b into a ] < < less than  <= less than or equal to > > greater than  >= greater than or equal to  != not equal to
  • 9. THE BOOLEAN TYPE • C contains a type named bool for conditions. • A condition can have one of two values: • true (corresponds to a non-zero value) • false (corresponds to zero value) • Boolean operators can be used to form more complex conditional expressions. • The and operator is && • The or operator is || • The not operator is !
  • 10. THE BOOLEAN TYPE • Truth table for "&&" (AND): Operand1 Operand2 Operand1 && Operand2 true true true true false false false true false false false false
  • 11. THE BOOLEAN TYPE • Truth table for “||" (OR): Operand1 Operand2 Operand1 || Operand2 true true true true false true false true true false false false
  • 12. THE BOOLEAN TYPE • Truth table for "!" (NOT): Operand !Operand true false false true
  • 13. A BOOLEAN TYPE • Assignments to bool type variables bool P = true; bool Q = false; bool R = true; bool S = P && Q; bool T = !Q || R; bool U = !(R && !Q);
  • 14. “IF” WITH A BLOCK OF STATEMENTS if (aValue <= 10) { printf("Answer is %.2fn", aValue); countB++; }
  • 15. POSITIVE OR NEGATIVE #include <stdio.h> main() { int number; clrscr(); printf(“Enter a number”); scanf(“%d”,&number); if (number>0) printf(“It is Positive”); getch(); }
  • 17. SYNTAX OF IF-ELSE STATEMENT if ( condition) statement; else statement;
  • 18. IF – ELSE WITH A BLOCK OF STATEMENTS if (aValue <= 10) { printf("Answer is %.2fn", aValue); countB++; } End if else { printf("Error occurredn"); countC++; } End else
  • 19. TO VOTE OR NOT TO VOTE #include<stdio.h> main() { int age; clrscr(); printf(“Enter your age”); scanf(“%d”,&age); if (age>=18) printf(“You are qualified to vote”); else printf(“Not qualified to vote”); getch(); }
  • 20. POSITIVE OR NEGATIVE #include <stdio.h> main() { int number; clrscr(); printf(“Enter a number”); scanf(“%d”,&number); if (number>0) printf(“Positive number”); else printf(“Negative number”); getch(); }