4
Most read
5
Most read
11
Most read
Presentation Topic: If-else
C if else
Introduction:-
The if statement is used to conditionally execute a statement or a
block of statements. Conditions can be true or false, execute one
thing when the condition is true, something else when the
condition is false.
C if else
Syntax:-
if (expression)
statement(s);
[else statement(s);]
C if else
Example :-
if (a == b)
printf ("%d is equal to %d", a, b);
else
printf ("%d is not equal to %d", a, b);
C if else
If-then statements :-
Syntax:-
if
(expression)
statement(s);
C if else
Note : There is no indentation rule in writing C programming, we can write the above
code in following ways :
If-then statements :-
Example:-
if (a == b)
printf ("%d is equal to %d", a, b);
else
printf ("%d is not equal to %d", a, b);
C if else
If-then statements :-
Example:-
if (a == b)
printf ("if a is equal to b");
printf ("%d is equal to %d", a, b);
if (a == b)
{
printf ("if a is equal to b"); printf
("%d is equal to %d", a,
b);
}
Note : The second way of writing code is a good practice.
C if else
#include<stdio.h>
main()
{
int num;
printf("Input a number : "); scanf("%d",&num); if(num>0)
{
printf("This is a positive integern");
}
else // else portion of if statement
{
printf(" This is not a positive integer..Try againn")
;
}
}
A complete example on conditional if-else statement:-
Example :-
C if else
►#include<stdio.h>
►main()
►{
►int num;
►printf("Input a number : "); scanf("%d",&num); if(num>0)
►{
►printf("This is a positive integern");
►}
►else // else portion of if statement
►{
►printf(" This is not a positive integer..Try againn")
►;
►}
►}
A complete example on conditional if-else statement:-
Example :-
C if else
Sequential if-then statements:-
Example :-
if (a == b)
printf ("a = b");
if (a == c)
printf ("a = c");
if (b == c)
printf ("b = c")
C if else
Multiway if-else-Statement :-
syntax :-
if (expression_1)
statement_1
else if (expression_2)
statement_2
.
.
.
else if (expression_n)
statement_n
else
other_statement
#include<stdio.h> main()
{
int num;
printf("Input score :"); scanf("%d",&num);
if (num>=90)
{
printf("Grade : Excellent");
}
else if(num>=80 && num<90)
{
printf("Grade : Very Good");
}
else if(num>=60 && num<80)
{
printf("Grade : Good");
}
else if(num>=50 && num<60)
{
printf("Grade : Average");
}
else if(num>=40 && num<50)
{
printf("Grade : Poor");
}
else
{
Multiway if-else-Statement :-
Example :-
C if else
C if else
Example
:-
#include<stdio.h>
main()
{
int num1=5, num2=3, num3=-12, min;
if(num1<num2)
{
if(num1<num3)
min = num1; else
min = num3;
}
else
{
if(num2<num3)
min = num2;
else
min = num3;
}
printf("Among %d, %d, %d minimum number is %d",num1
,num2,num3,min);
}
Nested if-then-else statements :-
If else

More Related Content

PPTX
C if else
PDF
basic of desicion control statement in python
PPTX
Arrays in Java
PPTX
Constructor in java
PPTX
ppt on pointers
PDF
Constructor and Destructor
PDF
Introduction to c++ ppt 1
PPTX
Constructor and destructor
C if else
basic of desicion control statement in python
Arrays in Java
Constructor in java
ppt on pointers
Constructor and Destructor
Introduction to c++ ppt 1
Constructor and destructor

What's hot (20)

PPTX
Chapter 4 NumPy Basics Arrays and Vectorized Computation (Part I).pptx
PDF
Python my sql database connection
DOC
Arrays and Strings
PPTX
Character set of c
PPSX
Type conversion
PPTX
Functions in c language
PPTX
Inline function
PPT
Function overloading(c++)
PPTX
Polymorphism in c++(ppt)
PPTX
for loop in java
PPTX
Functions in c++
PDF
Java conditional statements
PPTX
Issues in knowledge representation
PPTX
[OOP - Lec 07] Access Specifiers
PDF
C-- Sample Programs and Screenshots
PPT
Operators in c language
PPT
Java buzzwords
PPT
Passes of compilers
Chapter 4 NumPy Basics Arrays and Vectorized Computation (Part I).pptx
Python my sql database connection
Arrays and Strings
Character set of c
Type conversion
Functions in c language
Inline function
Function overloading(c++)
Polymorphism in c++(ppt)
for loop in java
Functions in c++
Java conditional statements
Issues in knowledge representation
[OOP - Lec 07] Access Specifiers
C-- Sample Programs and Screenshots
Operators in c language
Java buzzwords
Passes of compilers
Ad

Similar to If else (20)

RTF
control stucture in c language
PDF
control statement
PPT
Decisions in C or If condition
PPT
CONTROLSTRUCTURES.ppt
PPTX
Conditional statements
PDF
175035 cse lab-03
PPTX
M2 (1).pptxisedepofengiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
PDF
C programming
PDF
Programming Fundamentals Decisions
PPTX
control_structures_c_language_regarding how to represent the loop in language...
PDF
LET US C (5th EDITION) CHAPTER 2 ANSWERS
PDF
Loop's definition and practical code in C programming
PPTX
Najmul
PDF
C faq pdf
PDF
POP Unit 2.pptx.pdf for your time and gauss with example
PPTX
PDF
6 c control statements branching &amp; jumping
PPTX
Dti2143 chap 4 control statement part 2
PDF
LET US C (5th EDITION) CHAPTER 4 ANSWERS
PPTX
Decision making and branching
control stucture in c language
control statement
Decisions in C or If condition
CONTROLSTRUCTURES.ppt
Conditional statements
175035 cse lab-03
M2 (1).pptxisedepofengiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
C programming
Programming Fundamentals Decisions
control_structures_c_language_regarding how to represent the loop in language...
LET US C (5th EDITION) CHAPTER 2 ANSWERS
Loop's definition and practical code in C programming
Najmul
C faq pdf
POP Unit 2.pptx.pdf for your time and gauss with example
6 c control statements branching &amp; jumping
Dti2143 chap 4 control statement part 2
LET US C (5th EDITION) CHAPTER 4 ANSWERS
Decision making and branching
Ad

Recently uploaded (20)

PPTX
Sorting and Hashing in Data Structures with Algorithms, Techniques, Implement...
PPTX
Information Storage and Retrieval Techniques Unit III
PDF
UEFA_Embodied_Carbon_Emissions_Football_Infrastructure.pdf
PDF
Unit1 - AIML Chapter 1 concept and ethics
PPTX
CONTRACTS IN CONSTRUCTION PROJECTS: TYPES
PDF
Influence of Green Infrastructure on Residents’ Endorsement of the New Ecolog...
PPTX
Principal presentation for NAAC (1).pptx
PPTX
wireless networks, mobile computing.pptx
PPTX
Module 8- Technological and Communication Skills.pptx
PDF
MLpara ingenieira CIVIL, meca Y AMBIENTAL
PPTX
ASME PCC-02 TRAINING -DESKTOP-NLE5HNP.pptx
PPT
Chapter 1 - Introduction to Manufacturing Technology_2.ppt
PDF
distributed database system" (DDBS) is often used to refer to both the distri...
PPTX
Petroleum Refining & Petrochemicals.pptx
PPTX
AUTOMOTIVE ENGINE MANAGEMENT (MECHATRONICS).pptx
PDF
August -2025_Top10 Read_Articles_ijait.pdf
PDF
Accra-Kumasi Expressway - Prefeasibility Report Volume 1 of 7.11.2018.pdf
PDF
Introduction to Power System StabilityPS
PDF
August 2025 - Top 10 Read Articles in Network Security & Its Applications
PPTX
Software Engineering and software moduleing
Sorting and Hashing in Data Structures with Algorithms, Techniques, Implement...
Information Storage and Retrieval Techniques Unit III
UEFA_Embodied_Carbon_Emissions_Football_Infrastructure.pdf
Unit1 - AIML Chapter 1 concept and ethics
CONTRACTS IN CONSTRUCTION PROJECTS: TYPES
Influence of Green Infrastructure on Residents’ Endorsement of the New Ecolog...
Principal presentation for NAAC (1).pptx
wireless networks, mobile computing.pptx
Module 8- Technological and Communication Skills.pptx
MLpara ingenieira CIVIL, meca Y AMBIENTAL
ASME PCC-02 TRAINING -DESKTOP-NLE5HNP.pptx
Chapter 1 - Introduction to Manufacturing Technology_2.ppt
distributed database system" (DDBS) is often used to refer to both the distri...
Petroleum Refining & Petrochemicals.pptx
AUTOMOTIVE ENGINE MANAGEMENT (MECHATRONICS).pptx
August -2025_Top10 Read_Articles_ijait.pdf
Accra-Kumasi Expressway - Prefeasibility Report Volume 1 of 7.11.2018.pdf
Introduction to Power System StabilityPS
August 2025 - Top 10 Read Articles in Network Security & Its Applications
Software Engineering and software moduleing

If else

  • 2. C if else Introduction:- The if statement is used to conditionally execute a statement or a block of statements. Conditions can be true or false, execute one thing when the condition is true, something else when the condition is false.
  • 3. C if else Syntax:- if (expression) statement(s); [else statement(s);]
  • 4. C if else Example :- if (a == b) printf ("%d is equal to %d", a, b); else printf ("%d is not equal to %d", a, b);
  • 5. C if else If-then statements :- Syntax:- if (expression) statement(s);
  • 6. C if else Note : There is no indentation rule in writing C programming, we can write the above code in following ways : If-then statements :- Example:- if (a == b) printf ("%d is equal to %d", a, b); else printf ("%d is not equal to %d", a, b);
  • 7. C if else If-then statements :- Example:- if (a == b) printf ("if a is equal to b"); printf ("%d is equal to %d", a, b); if (a == b) { printf ("if a is equal to b"); printf ("%d is equal to %d", a, b); } Note : The second way of writing code is a good practice.
  • 8. C if else #include<stdio.h> main() { int num; printf("Input a number : "); scanf("%d",&num); if(num>0) { printf("This is a positive integern"); } else // else portion of if statement { printf(" This is not a positive integer..Try againn") ; } } A complete example on conditional if-else statement:- Example :-
  • 9. C if else ►#include<stdio.h> ►main() ►{ ►int num; ►printf("Input a number : "); scanf("%d",&num); if(num>0) ►{ ►printf("This is a positive integern"); ►} ►else // else portion of if statement ►{ ►printf(" This is not a positive integer..Try againn") ►; ►} ►} A complete example on conditional if-else statement:- Example :-
  • 10. C if else Sequential if-then statements:- Example :- if (a == b) printf ("a = b"); if (a == c) printf ("a = c"); if (b == c) printf ("b = c")
  • 11. C if else Multiway if-else-Statement :- syntax :- if (expression_1) statement_1 else if (expression_2) statement_2 . . . else if (expression_n) statement_n else other_statement
  • 12. #include<stdio.h> main() { int num; printf("Input score :"); scanf("%d",&num); if (num>=90) { printf("Grade : Excellent"); } else if(num>=80 && num<90) { printf("Grade : Very Good"); } else if(num>=60 && num<80) { printf("Grade : Good"); } else if(num>=50 && num<60) { printf("Grade : Average"); } else if(num>=40 && num<50) { printf("Grade : Poor"); } else { Multiway if-else-Statement :- Example :- C if else
  • 13. C if else Example :- #include<stdio.h> main() { int num1=5, num2=3, num3=-12, min; if(num1<num2) { if(num1<num3) min = num1; else min = num3; } else { if(num2<num3) min = num2; else min = num3; } printf("Among %d, %d, %d minimum number is %d",num1 ,num2,num3,min); } Nested if-then-else statements :-