SlideShare une entreprise Scribd logo
1  sur  22
Télécharger pour lire hors ligne
A
PRESENTATION ON CONDITIONAL
STATEMENT IN “C”
LANGUAGE
Shaina Arora
Assistant Prof. (CS) Dept. AIET
C0NTENT
1. INTRODUCTION
2. IF CONDITION
3. IF ELSE CONDITION
4. NESTED IF ELSE CONDITION
5. LADDER ELSE IF CONDITION
6. SWITCH CASE CONDITION
7. BREAK STATEMENT
8. GOTO LABEL STATEMENT
9. CONTINUE STATEMENT
INTRODUCTION
Conditional Statements Are Used To Execute A
Set Of Statements On Some Conditions. It
Provides A Unit Of Block In Which We Can
Either One Statement Or More Than One
Statments. If The Given Condition Is True Then
The Set Of Statements Are Executed Otherwise
Body Is Skipped.
IF CONDITION
It is conditional statement, which is used to
execute a set of statement on some conditions.
The condition must be of Boolean type
expression.
An expression, which returns only two value
either TRUE or FALSE, is known as Boolean type
expression.
Syntax: - if
(condition)
{
………………..
………………..
}
In Another Words, It Can Also Be Said As Single
Blocked Conditional Statements In Which Only One
Part Is Mentioned. That Is Known As TRUE Part.
Example #1: C if statement
// Program to display a number if user enters negative number
// If user enters positive number, that number won't be displayed
#include <stdio.h>
#include<conio.h>
void main()
{
int number;
printf("Enter an integer: ");
scanf("%d", &number);
// Test expression is true if number is less than 0
if (number < 0)
{
printf("You entered %d.n", number);
}
printf("The if statement is easy.");
getch();
}
IF ELSE CONDITION
It Is Known As Double Blocked Conditional
Statements .It Means, It Has TRUE Parts As
Well As FALSE Part.
If The Given Condition Is True Then The
True Part Is Executed Otherwise False Part Is
Executed.
SYNTAX: -
IF (CONDITION)
{
………………..
………………..
}
ELSE
{
………………..
………………..
}
=
EXAMPLE #2: C IF...ELSE STATEMENT
// PROGRAM TO CHECK WHETHER AN INTEGER ENTERED BY
THE USER IS ODD OR EVEN
#include <stdio.h>
#include<conio.h>
void main()
{
int number;
printf("Enter an integer: ");
scanf("%d",&number);
// True if remainder is 0
if( number%2 == 0 )
printf("%d is an even integer.",number);
else
printf("%d is an odd integer.",number);
getch();
}
NESTED IF ELSE
Using Of One If Statement Within Another If Statement
Is Known As Nested Of If else Statement.
syntax-
if (……….)
{
………….
………….
if (………)
{
…………..
…………..
}
else
{
…………
…………
}
#Include <stdio.h>
#Include<conio.h>
Void main()
{
Int a,b;
Clrscr();
printf(“Enter Two
Numbers”);
scanf(“%d%d”,&a,&
b);
If(a==b)
{
Printf(“a is equal to
else
If(a>b)
{
Printf(“a is greater”);
}
else
{
Printf(“b is greater”);
}
getch();
}
Q: - WAP to input two numbers and print the greatest
numbers.
LADDER ELSE IF CONDITION
When We Want To Specify Condition With Else
Part Then We Have To Use Ladder Of If Statement.
In This Case If The Condition Specified With First
If -Statement Is False, Then Control Goes To
Second ―Else If‖ Statement. If It Is True Then Part
(2) Is Executed Otherwise Control Goes To Third
―Else-if‖ Statement. If It Is True, Then Part (3) Is
Executed Otherwise Part (4) Is Executed.
If The Condition Specified With First If Statement
Is True, Then Part (1) Is Executed.
Syntax: -
if (……….)
{
………….
…………. 1
}
else if (…….)
{
…………
………… 2
}
else if (………)
{
………….
…………. 3
}
else
{
………….
…………. 4
Include <stdio.h>
Include<conio.h>
Void main()
{
Int a,b,c;
Clrscr();
printf ("n enter first number: -");
scanf("%d",&a);
printf("n enter secend number : -");
scanf("%d",&b);
printf("n enter third number : -");
scanf("%d",&c);
if(a>b)
{
if(a>c)
{
printf("n a is greatest: -");
}
else
{
printf("n c is greatest: -");
}
}
else
if(b>c)
{
printf("n b is greatest: -");
}
else
{
printf("n c is greatest: -");
}
getch();
}
Q: - WAP to input three number and print the greatest
number.
SWITCH CASE CONDITION
It Is Multiple Conditioned Checking
Statements, Which Is Generally Used For
Menu- Driven Program Where We Have To
Select One Option Out Of Several Options At
A Time.
The number of ―case within switch –
statement is same as the number of options
present in menu. Each ―case is used to do
only one work at a time.
Default section: -
It is optional section, which is generally used
for error handling. It means by using this
section we can displays error messages. In case
of wrong choice entry or out of range choice. It
is automatically executed when any user
enters wrong choice.
SWITCH CASE FLOW CHART
#include<stdio.h>
#include<conio.h>
void main()
{
int a;
clrscr();
printf("enter day numbern****************");
scanf("%d",&a);
switch(a)
{
case 1:
printf("monday");
break;
case 2:
printf("tuesday");
break;
case 3:
printf("wednesday");
break;
case 4:
printf("thirsday");
break;
case 5:
printf("friday");
break;
case 6:
printf("saturday");
break;
case 7:
printf("sunday");
break;
default:
printf("day not
vailedn**************");
}
getch();
}
Q: - WAP to accept day no. (1 to 7) and print the day name
GOTO LABELCONDITION
This statement is used to send the control from
one position to any desired position within a
program.
Since program is executed from top to bottom
statement by statement. So if we want to
execute certain part of program directly, then
we can use this statement to do the same work.
Label: -
May Be Any User Defined Name Or Identifiers. It Is
Just Like A Variable But Not A Variable. It Should Not
Be Declared As Variables By Any Data Type.
Label Must Be Indicated At That Place Where We Want
To Send The Control And It Must Be Followed By Colon
(:) Sign.
When It Is Directly Used In A Program Then It Just
Works As Infinite Loop. So It Must Be Used On Some
Condition.
Syn: -
goto label;
Ex: -
void main ()
{
ram:
-----
------
-------
---------
goto ram;
----------
----------
---------
}
exp227-jan-170127160848 (3) (1).pdf

Contenu connexe

Similaire à exp227-jan-170127160848 (3) (1).pdf

1584503386 1st chap
1584503386 1st chap1584503386 1st chap
1584503386 1st chapthuhiendtk4
 
unit 2-Control Structures.pptx
unit 2-Control Structures.pptxunit 2-Control Structures.pptx
unit 2-Control Structures.pptxishaparte4
 
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
 
Conditional statements
Conditional statementsConditional statements
Conditional statementsNabishaAK
 
Programming fundamental 02
Programming fundamental 02Programming fundamental 02
Programming fundamental 02Suhail Akraam
 
CONTROLSTRUCTURES.ppt
CONTROLSTRUCTURES.pptCONTROLSTRUCTURES.ppt
CONTROLSTRUCTURES.pptSanjjaayyy
 
Branching statements
Branching statementsBranching statements
Branching statementsArunMK17
 
Decision making using if statement
Decision making using if statementDecision making using if statement
Decision making using if statementCHANDAN KUMAR
 
Control structuresin c
Control structuresin cControl structuresin c
Control structuresin cVikash Dhal
 
Fundamental of Information Technology - UNIT 8
Fundamental of Information Technology - UNIT 8Fundamental of Information Technology - UNIT 8
Fundamental of Information Technology - UNIT 8Shipra Swati
 
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
 
Dti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selectionDti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selectionalish sha
 

Similaire à exp227-jan-170127160848 (3) (1).pdf (20)

1584503386 1st chap
1584503386 1st chap1584503386 1st chap
1584503386 1st chap
 
unit 2-Control Structures.pptx
unit 2-Control Structures.pptxunit 2-Control Structures.pptx
unit 2-Control Structures.pptx
 
C Unit-2.ppt
C Unit-2.pptC Unit-2.ppt
C Unit-2.ppt
 
Elements of programming
Elements of programmingElements of programming
Elements of programming
 
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
 
3. control statement
3. control statement3. control statement
3. control statement
 
Conditional statements
Conditional statementsConditional statements
Conditional statements
 
Decision Making and Branching
Decision Making and BranchingDecision Making and Branching
Decision Making and Branching
 
Programming fundamental 02
Programming fundamental 02Programming fundamental 02
Programming fundamental 02
 
CONTROLSTRUCTURES.ppt
CONTROLSTRUCTURES.pptCONTROLSTRUCTURES.ppt
CONTROLSTRUCTURES.ppt
 
Lec 10
Lec 10Lec 10
Lec 10
 
C PROGRAMMING p-3.pptx
C PROGRAMMING p-3.pptxC PROGRAMMING p-3.pptx
C PROGRAMMING p-3.pptx
 
Branching statements
Branching statementsBranching statements
Branching statements
 
Decision making using if statement
Decision making using if statementDecision making using if statement
Decision making using if statement
 
Control structuresin c
Control structuresin cControl structuresin c
Control structuresin c
 
week4_lec2_switch-statement.pptx
week4_lec2_switch-statement.pptxweek4_lec2_switch-statement.pptx
week4_lec2_switch-statement.pptx
 
CH-4 (1).pptx
CH-4 (1).pptxCH-4 (1).pptx
CH-4 (1).pptx
 
Fundamental of Information Technology - UNIT 8
Fundamental of Information Technology - UNIT 8Fundamental of Information Technology - UNIT 8
Fundamental of Information Technology - UNIT 8
 
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
 
Dti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selectionDti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selection
 

Plus de mounikanarra3

functionsinc-130108032745-phpapp01.pdf
functionsinc-130108032745-phpapp01.pdffunctionsinc-130108032745-phpapp01.pdf
functionsinc-130108032745-phpapp01.pdfmounikanarra3
 
travelingsalesmanproblem-170122053648.pdf
travelingsalesmanproblem-170122053648.pdftravelingsalesmanproblem-170122053648.pdf
travelingsalesmanproblem-170122053648.pdfmounikanarra3
 
Space complexity-DAA.pptx
Space complexity-DAA.pptxSpace complexity-DAA.pptx
Space complexity-DAA.pptxmounikanarra3
 
(PAD_5)Dynamic_Programming.ppt
(PAD_5)Dynamic_Programming.ppt(PAD_5)Dynamic_Programming.ppt
(PAD_5)Dynamic_Programming.pptmounikanarra3
 
sequencediagram-150302224029-conversion-gate01 (1).pdf
sequencediagram-150302224029-conversion-gate01 (1).pdfsequencediagram-150302224029-conversion-gate01 (1).pdf
sequencediagram-150302224029-conversion-gate01 (1).pdfmounikanarra3
 
stephenhawkingppt-160402093003.pdf
stephenhawkingppt-160402093003.pdfstephenhawkingppt-160402093003.pdf
stephenhawkingppt-160402093003.pdfmounikanarra3
 

Plus de mounikanarra3 (15)

unit-2.pdf
unit-2.pdfunit-2.pdf
unit-2.pdf
 
Unit - 4.pptx
Unit - 4.pptxUnit - 4.pptx
Unit - 4.pptx
 
UNIT-1 (4).pdf
UNIT-1 (4).pdfUNIT-1 (4).pdf
UNIT-1 (4).pdf
 
functionsinc-130108032745-phpapp01.pdf
functionsinc-130108032745-phpapp01.pdffunctionsinc-130108032745-phpapp01.pdf
functionsinc-130108032745-phpapp01.pdf
 
travelingsalesmanproblem-170122053648.pdf
travelingsalesmanproblem-170122053648.pdftravelingsalesmanproblem-170122053648.pdf
travelingsalesmanproblem-170122053648.pdf
 
Space complexity-DAA.pptx
Space complexity-DAA.pptxSpace complexity-DAA.pptx
Space complexity-DAA.pptx
 
EEM MID2.PPT.pptx
EEM MID2.PPT.pptxEEM MID2.PPT.pptx
EEM MID2.PPT.pptx
 
MID2 UML (1).pptx
MID2 UML (1).pptxMID2 UML (1).pptx
MID2 UML (1).pptx
 
(PAD_5)Dynamic_Programming.ppt
(PAD_5)Dynamic_Programming.ppt(PAD_5)Dynamic_Programming.ppt
(PAD_5)Dynamic_Programming.ppt
 
sequencediagram-150302224029-conversion-gate01 (1).pdf
sequencediagram-150302224029-conversion-gate01 (1).pdfsequencediagram-150302224029-conversion-gate01 (1).pdf
sequencediagram-150302224029-conversion-gate01 (1).pdf
 
UML.PPT.pptx
UML.PPT.pptxUML.PPT.pptx
UML.PPT.pptx
 
stephenhawkingppt-160402093003.pdf
stephenhawkingppt-160402093003.pdfstephenhawkingppt-160402093003.pdf
stephenhawkingppt-160402093003.pdf
 
CP-STRING (1).ppt
CP-STRING (1).pptCP-STRING (1).ppt
CP-STRING (1).ppt
 
Array.pdf
Array.pdfArray.pdf
Array.pdf
 
routing.pptx
routing.pptxrouting.pptx
routing.pptx
 

Dernier

Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoorTop Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoordharasingh5698
 
Minimum and Maximum Modes of microprocessor 8086
Minimum and Maximum Modes of microprocessor 8086Minimum and Maximum Modes of microprocessor 8086
Minimum and Maximum Modes of microprocessor 8086anil_gaur
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityMorshed Ahmed Rahath
 
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Standamitlee9823
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Bookingdharasingh5698
 
22-prompt engineering noted slide shown.pdf
22-prompt engineering noted slide shown.pdf22-prompt engineering noted slide shown.pdf
22-prompt engineering noted slide shown.pdf203318pmpc
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueBhangaleSonal
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayEpec Engineered Technologies
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlysanyuktamishra911
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startQuintin Balsdon
 
Unit 2- Effective stress & Permeability.pdf
Unit 2- Effective stress & Permeability.pdfUnit 2- Effective stress & Permeability.pdf
Unit 2- Effective stress & Permeability.pdfRagavanV2
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXssuser89054b
 
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...soginsider
 
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Bookingroncy bisnoi
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfRagavanV2
 

Dernier (20)

Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
 
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoorTop Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
 
Minimum and Maximum Modes of microprocessor 8086
Minimum and Maximum Modes of microprocessor 8086Minimum and Maximum Modes of microprocessor 8086
Minimum and Maximum Modes of microprocessor 8086
 
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna Municipality
 
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
 
22-prompt engineering noted slide shown.pdf
22-prompt engineering noted slide shown.pdf22-prompt engineering noted slide shown.pdf
22-prompt engineering noted slide shown.pdf
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 
Unit 2- Effective stress & Permeability.pdf
Unit 2- Effective stress & Permeability.pdfUnit 2- Effective stress & Permeability.pdf
Unit 2- Effective stress & Permeability.pdf
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
 
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdf
 

exp227-jan-170127160848 (3) (1).pdf

  • 1. A PRESENTATION ON CONDITIONAL STATEMENT IN “C” LANGUAGE Shaina Arora Assistant Prof. (CS) Dept. AIET
  • 2. C0NTENT 1. INTRODUCTION 2. IF CONDITION 3. IF ELSE CONDITION 4. NESTED IF ELSE CONDITION 5. LADDER ELSE IF CONDITION 6. SWITCH CASE CONDITION 7. BREAK STATEMENT 8. GOTO LABEL STATEMENT 9. CONTINUE STATEMENT
  • 3. INTRODUCTION Conditional Statements Are Used To Execute A Set Of Statements On Some Conditions. It Provides A Unit Of Block In Which We Can Either One Statement Or More Than One Statments. If The Given Condition Is True Then The Set Of Statements Are Executed Otherwise Body Is Skipped.
  • 4. IF CONDITION It is conditional statement, which is used to execute a set of statement on some conditions. The condition must be of Boolean type expression. An expression, which returns only two value either TRUE or FALSE, is known as Boolean type expression.
  • 5. Syntax: - if (condition) { ……………….. ……………….. } In Another Words, It Can Also Be Said As Single Blocked Conditional Statements In Which Only One Part Is Mentioned. That Is Known As TRUE Part.
  • 6. Example #1: C if statement // Program to display a number if user enters negative number // If user enters positive number, that number won't be displayed #include <stdio.h> #include<conio.h> void main() { int number; printf("Enter an integer: "); scanf("%d", &number); // Test expression is true if number is less than 0 if (number < 0) { printf("You entered %d.n", number); } printf("The if statement is easy."); getch(); }
  • 7. IF ELSE CONDITION It Is Known As Double Blocked Conditional Statements .It Means, It Has TRUE Parts As Well As FALSE Part. If The Given Condition Is True Then The True Part Is Executed Otherwise False Part Is Executed.
  • 9. EXAMPLE #2: C IF...ELSE STATEMENT // PROGRAM TO CHECK WHETHER AN INTEGER ENTERED BY THE USER IS ODD OR EVEN #include <stdio.h> #include<conio.h> void main() { int number; printf("Enter an integer: "); scanf("%d",&number); // True if remainder is 0 if( number%2 == 0 ) printf("%d is an even integer.",number); else printf("%d is an odd integer.",number); getch(); }
  • 10. NESTED IF ELSE Using Of One If Statement Within Another If Statement Is Known As Nested Of If else Statement. syntax- if (……….) { …………. …………. if (………) { ………….. ………….. } else { ………… ………… }
  • 11. #Include <stdio.h> #Include<conio.h> Void main() { Int a,b; Clrscr(); printf(“Enter Two Numbers”); scanf(“%d%d”,&a,& b); If(a==b) { Printf(“a is equal to else If(a>b) { Printf(“a is greater”); } else { Printf(“b is greater”); } getch(); } Q: - WAP to input two numbers and print the greatest numbers.
  • 12. LADDER ELSE IF CONDITION When We Want To Specify Condition With Else Part Then We Have To Use Ladder Of If Statement. In This Case If The Condition Specified With First If -Statement Is False, Then Control Goes To Second ―Else If‖ Statement. If It Is True Then Part (2) Is Executed Otherwise Control Goes To Third ―Else-if‖ Statement. If It Is True, Then Part (3) Is Executed Otherwise Part (4) Is Executed. If The Condition Specified With First If Statement Is True, Then Part (1) Is Executed.
  • 13. Syntax: - if (……….) { …………. …………. 1 } else if (…….) { ………… ………… 2 } else if (………) { …………. …………. 3 } else { …………. …………. 4
  • 14. Include <stdio.h> Include<conio.h> Void main() { Int a,b,c; Clrscr(); printf ("n enter first number: -"); scanf("%d",&a); printf("n enter secend number : -"); scanf("%d",&b); printf("n enter third number : -"); scanf("%d",&c); if(a>b) { if(a>c) { printf("n a is greatest: -"); } else { printf("n c is greatest: -"); } } else if(b>c) { printf("n b is greatest: -"); } else { printf("n c is greatest: -"); } getch(); } Q: - WAP to input three number and print the greatest number.
  • 15. SWITCH CASE CONDITION It Is Multiple Conditioned Checking Statements, Which Is Generally Used For Menu- Driven Program Where We Have To Select One Option Out Of Several Options At A Time. The number of ―case within switch – statement is same as the number of options present in menu. Each ―case is used to do only one work at a time.
  • 16. Default section: - It is optional section, which is generally used for error handling. It means by using this section we can displays error messages. In case of wrong choice entry or out of range choice. It is automatically executed when any user enters wrong choice.
  • 18. #include<stdio.h> #include<conio.h> void main() { int a; clrscr(); printf("enter day numbern****************"); scanf("%d",&a); switch(a) { case 1: printf("monday"); break; case 2: printf("tuesday"); break; case 3: printf("wednesday"); break; case 4: printf("thirsday"); break; case 5: printf("friday"); break; case 6: printf("saturday"); break; case 7: printf("sunday"); break; default: printf("day not vailedn**************"); } getch(); } Q: - WAP to accept day no. (1 to 7) and print the day name
  • 19. GOTO LABELCONDITION This statement is used to send the control from one position to any desired position within a program. Since program is executed from top to bottom statement by statement. So if we want to execute certain part of program directly, then we can use this statement to do the same work.
  • 20. Label: - May Be Any User Defined Name Or Identifiers. It Is Just Like A Variable But Not A Variable. It Should Not Be Declared As Variables By Any Data Type. Label Must Be Indicated At That Place Where We Want To Send The Control And It Must Be Followed By Colon (:) Sign. When It Is Directly Used In A Program Then It Just Works As Infinite Loop. So It Must Be Used On Some Condition.
  • 21. Syn: - goto label; Ex: - void main () { ram: ----- ------ ------- --------- goto ram; ---------- ---------- --------- }