SlideShare uma empresa Scribd logo
1 de 22
Baixar para ler offline
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;
----------
----------
---------
}
Conditional Statement in C Language

Mais conteúdo relacionado

Mais procurados

Mais procurados (20)

CONDITIONAL STATEMENT IN C LANGUAGE
CONDITIONAL STATEMENT IN C LANGUAGECONDITIONAL STATEMENT IN C LANGUAGE
CONDITIONAL STATEMENT IN C LANGUAGE
 
Control statements in c
Control statements in cControl statements in c
Control statements in c
 
C++ Overview PPT
C++ Overview PPTC++ Overview PPT
C++ Overview PPT
 
Control Statement programming
Control Statement programmingControl Statement programming
Control Statement programming
 
Functions in python slide share
Functions in python slide shareFunctions in python slide share
Functions in python slide share
 
Types of loops in c language
Types of loops in c languageTypes of loops in c language
Types of loops in c language
 
Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++
 
FUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPTFUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPT
 
Operators in C Programming
Operators in C ProgrammingOperators in C Programming
Operators in C Programming
 
Structure of a C program
Structure of a C programStructure of a C program
Structure of a C program
 
10. switch case
10. switch case10. switch case
10. switch case
 
Control statements
Control statementsControl statements
Control statements
 
RECURSION IN C
RECURSION IN C RECURSION IN C
RECURSION IN C
 
String functions in C
String functions in CString functions in C
String functions in C
 
Decision making statements in C programming
Decision making statements in C programmingDecision making statements in C programming
Decision making statements in C programming
 
Pointer in c
Pointer in cPointer in c
Pointer in c
 
Array in c
Array in cArray in c
Array in c
 
Introduction to c++ ppt 1
Introduction to c++ ppt 1Introduction to c++ ppt 1
Introduction to c++ ppt 1
 
Programming in ansi C by Balaguruswami
Programming in ansi C by BalaguruswamiProgramming in ansi C by Balaguruswami
Programming in ansi C by Balaguruswami
 
Switch statement, break statement, go to statement
Switch statement, break statement, go to statementSwitch statement, break statement, go to statement
Switch statement, break statement, go to statement
 

Destaque

9. statements (conditional statements)
9. statements (conditional statements)9. statements (conditional statements)
9. statements (conditional statements)Way2itech
 
Selection statements
Selection statementsSelection statements
Selection statementsHarsh Dabas
 
SULTHAN's - C Programming Language notes
SULTHAN's - C Programming Language notesSULTHAN's - C Programming Language notes
SULTHAN's - C Programming Language notesSULTHAN BASHA
 
Selection Statements in C Programming
Selection Statements in C ProgrammingSelection Statements in C Programming
Selection Statements in C ProgrammingKamal Acharya
 
Complete C programming Language Course
Complete C programming Language CourseComplete C programming Language Course
Complete C programming Language CourseVivek chan
 
Conditional statement
Conditional statementConditional statement
Conditional statementMaxie Santos
 

Destaque (7)

9. statements (conditional statements)
9. statements (conditional statements)9. statements (conditional statements)
9. statements (conditional statements)
 
Selection statements
Selection statementsSelection statements
Selection statements
 
Lecture03(c expressions & operators)
Lecture03(c expressions & operators)Lecture03(c expressions & operators)
Lecture03(c expressions & operators)
 
SULTHAN's - C Programming Language notes
SULTHAN's - C Programming Language notesSULTHAN's - C Programming Language notes
SULTHAN's - C Programming Language notes
 
Selection Statements in C Programming
Selection Statements in C ProgrammingSelection Statements in C Programming
Selection Statements in C Programming
 
Complete C programming Language Course
Complete C programming Language CourseComplete C programming Language Course
Complete C programming Language Course
 
Conditional statement
Conditional statementConditional statement
Conditional statement
 

Semelhante a Conditional Statement in C Language

exp227-jan-170127160848 (3) (1).pdf
exp227-jan-170127160848 (3) (1).pdfexp227-jan-170127160848 (3) (1).pdf
exp227-jan-170127160848 (3) (1).pdfmounikanarra3
 
BHARGAVISTATEMENTS.PPT.pptx
BHARGAVISTATEMENTS.PPT.pptxBHARGAVISTATEMENTS.PPT.pptx
BHARGAVISTATEMENTS.PPT.pptxSasideepa
 
Control statements-Computer programming
Control statements-Computer programmingControl statements-Computer programming
Control statements-Computer programmingnmahi96
 
computer programming Control Statements.pptx
computer programming Control Statements.pptxcomputer programming Control Statements.pptx
computer programming Control Statements.pptxeaglesniper008
 
C Programming: Control Structure
C Programming: Control StructureC Programming: Control Structure
C Programming: Control StructureSokngim Sa
 
Control structure of c
Control structure of cControl structure of c
Control structure of cKomal Kotak
 
unit 2-Control Structures.pptx
unit 2-Control Structures.pptxunit 2-Control Structures.pptx
unit 2-Control Structures.pptxishaparte4
 
1584503386 1st chap
1584503386 1st chap1584503386 1st chap
1584503386 1st chapthuhiendtk4
 
Conditional statements
Conditional statementsConditional statements
Conditional statementsNabishaAK
 
C programming Control Structure.pptx
C programming Control Structure.pptxC programming Control Structure.pptx
C programming Control Structure.pptxDEEPAK948083
 
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
 
Programming fundamental 02
Programming fundamental 02Programming fundamental 02
Programming fundamental 02Suhail Akraam
 
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
 

Semelhante a Conditional Statement in C Language (20)

exp227-jan-170127160848 (3) (1).pdf
exp227-jan-170127160848 (3) (1).pdfexp227-jan-170127160848 (3) (1).pdf
exp227-jan-170127160848 (3) (1).pdf
 
BHARGAVISTATEMENTS.PPT.pptx
BHARGAVISTATEMENTS.PPT.pptxBHARGAVISTATEMENTS.PPT.pptx
BHARGAVISTATEMENTS.PPT.pptx
 
Control statements-Computer programming
Control statements-Computer programmingControl statements-Computer programming
Control statements-Computer programming
 
computer programming Control Statements.pptx
computer programming Control Statements.pptxcomputer programming Control Statements.pptx
computer programming Control Statements.pptx
 
C Programming: Control Structure
C Programming: Control StructureC Programming: Control Structure
C Programming: Control Structure
 
Control structure of c
Control structure of cControl structure of c
Control structure of c
 
unit 2-Control Structures.pptx
unit 2-Control Structures.pptxunit 2-Control Structures.pptx
unit 2-Control Structures.pptx
 
1584503386 1st chap
1584503386 1st chap1584503386 1st chap
1584503386 1st chap
 
Conditional statements
Conditional statementsConditional statements
Conditional statements
 
C programming Control Structure.pptx
C programming Control Structure.pptxC programming Control Structure.pptx
C programming Control Structure.pptx
 
Decision Making and Branching
Decision Making and BranchingDecision Making and Branching
Decision Making and Branching
 
Elements of programming
Elements of programmingElements of programming
Elements of programming
 
3. control statement
3. control statement3. control statement
3. control statement
 
Lec 10
Lec 10Lec 10
Lec 10
 
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
 
Programming fundamental 02
Programming fundamental 02Programming fundamental 02
Programming fundamental 02
 
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
 
C Unit-2.ppt
C Unit-2.pptC Unit-2.ppt
C Unit-2.ppt
 

Último

News web APP using NEWS API for web platform to enhancing user experience
News web APP using NEWS API for web platform to enhancing user experienceNews web APP using NEWS API for web platform to enhancing user experience
News web APP using NEWS API for web platform to enhancing user experienceAkashJha84
 
solar wireless electric vechicle charging system
solar wireless electric vechicle charging systemsolar wireless electric vechicle charging system
solar wireless electric vechicle charging systemgokuldongala
 
sdfsadopkjpiosufoiasdoifjasldkjfl a asldkjflaskdjflkjsdsdf
sdfsadopkjpiosufoiasdoifjasldkjfl a asldkjflaskdjflkjsdsdfsdfsadopkjpiosufoiasdoifjasldkjfl a asldkjflaskdjflkjsdsdf
sdfsadopkjpiosufoiasdoifjasldkjfl a asldkjflaskdjflkjsdsdfJulia Kaye
 
Technical Management of cement industry.pdf
Technical Management of cement industry.pdfTechnical Management of cement industry.pdf
Technical Management of cement industry.pdfMadan Karki
 
cloud computing notes for anna university syllabus
cloud computing notes for anna university syllabuscloud computing notes for anna university syllabus
cloud computing notes for anna university syllabusViolet Violet
 
Popular-NO1 Kala Jadu Expert Specialist In Germany Kala Jadu Expert Specialis...
Popular-NO1 Kala Jadu Expert Specialist In Germany Kala Jadu Expert Specialis...Popular-NO1 Kala Jadu Expert Specialist In Germany Kala Jadu Expert Specialis...
Popular-NO1 Kala Jadu Expert Specialist In Germany Kala Jadu Expert Specialis...Amil baba
 
Tachyon 100G PCB Performance Attributes and Applications
Tachyon 100G PCB Performance Attributes and ApplicationsTachyon 100G PCB Performance Attributes and Applications
Tachyon 100G PCB Performance Attributes and ApplicationsEpec Engineered Technologies
 
Introduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHIntroduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHC Sai Kiran
 
Renewable Energy & Entrepreneurship Workshop_21Feb2024.pdf
Renewable Energy & Entrepreneurship Workshop_21Feb2024.pdfRenewable Energy & Entrepreneurship Workshop_21Feb2024.pdf
Renewable Energy & Entrepreneurship Workshop_21Feb2024.pdfodunowoeminence2019
 
me3493 manufacturing technology unit 1 Part A
me3493 manufacturing technology unit 1 Part Ame3493 manufacturing technology unit 1 Part A
me3493 manufacturing technology unit 1 Part Akarthi keyan
 
Transforming Process Safety Management: Challenges, Benefits, and Transition ...
Transforming Process Safety Management: Challenges, Benefits, and Transition ...Transforming Process Safety Management: Challenges, Benefits, and Transition ...
Transforming Process Safety Management: Challenges, Benefits, and Transition ...soginsider
 
nvidia AI-gtc 2024 partial slide deck.pptx
nvidia AI-gtc 2024 partial slide deck.pptxnvidia AI-gtc 2024 partial slide deck.pptx
nvidia AI-gtc 2024 partial slide deck.pptxjasonsedano2
 
Technology Features of Apollo HDD Machine, Its Technical Specification with C...
Technology Features of Apollo HDD Machine, Its Technical Specification with C...Technology Features of Apollo HDD Machine, Its Technical Specification with C...
Technology Features of Apollo HDD Machine, Its Technical Specification with C...Apollo Techno Industries Pvt Ltd
 
The relationship between iot and communication technology
The relationship between iot and communication technologyThe relationship between iot and communication technology
The relationship between iot and communication technologyabdulkadirmukarram03
 
Strategies of Urban Morphologyfor Improving Outdoor Thermal Comfort and Susta...
Strategies of Urban Morphologyfor Improving Outdoor Thermal Comfort and Susta...Strategies of Urban Morphologyfor Improving Outdoor Thermal Comfort and Susta...
Strategies of Urban Morphologyfor Improving Outdoor Thermal Comfort and Susta...amrabdallah9
 
How to Write a Good Scientific Paper.pdf
How to Write a Good Scientific Paper.pdfHow to Write a Good Scientific Paper.pdf
How to Write a Good Scientific Paper.pdfRedhwan Qasem Shaddad
 

Último (20)

News web APP using NEWS API for web platform to enhancing user experience
News web APP using NEWS API for web platform to enhancing user experienceNews web APP using NEWS API for web platform to enhancing user experience
News web APP using NEWS API for web platform to enhancing user experience
 
Lecture 2 .pptx
Lecture 2                            .pptxLecture 2                            .pptx
Lecture 2 .pptx
 
solar wireless electric vechicle charging system
solar wireless electric vechicle charging systemsolar wireless electric vechicle charging system
solar wireless electric vechicle charging system
 
sdfsadopkjpiosufoiasdoifjasldkjfl a asldkjflaskdjflkjsdsdf
sdfsadopkjpiosufoiasdoifjasldkjfl a asldkjflaskdjflkjsdsdfsdfsadopkjpiosufoiasdoifjasldkjfl a asldkjflaskdjflkjsdsdf
sdfsadopkjpiosufoiasdoifjasldkjfl a asldkjflaskdjflkjsdsdf
 
Technical Management of cement industry.pdf
Technical Management of cement industry.pdfTechnical Management of cement industry.pdf
Technical Management of cement industry.pdf
 
cloud computing notes for anna university syllabus
cloud computing notes for anna university syllabuscloud computing notes for anna university syllabus
cloud computing notes for anna university syllabus
 
Popular-NO1 Kala Jadu Expert Specialist In Germany Kala Jadu Expert Specialis...
Popular-NO1 Kala Jadu Expert Specialist In Germany Kala Jadu Expert Specialis...Popular-NO1 Kala Jadu Expert Specialist In Germany Kala Jadu Expert Specialis...
Popular-NO1 Kala Jadu Expert Specialist In Germany Kala Jadu Expert Specialis...
 
Tachyon 100G PCB Performance Attributes and Applications
Tachyon 100G PCB Performance Attributes and ApplicationsTachyon 100G PCB Performance Attributes and Applications
Tachyon 100G PCB Performance Attributes and Applications
 
Introduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHIntroduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECH
 
Renewable Energy & Entrepreneurship Workshop_21Feb2024.pdf
Renewable Energy & Entrepreneurship Workshop_21Feb2024.pdfRenewable Energy & Entrepreneurship Workshop_21Feb2024.pdf
Renewable Energy & Entrepreneurship Workshop_21Feb2024.pdf
 
me3493 manufacturing technology unit 1 Part A
me3493 manufacturing technology unit 1 Part Ame3493 manufacturing technology unit 1 Part A
me3493 manufacturing technology unit 1 Part A
 
Transforming Process Safety Management: Challenges, Benefits, and Transition ...
Transforming Process Safety Management: Challenges, Benefits, and Transition ...Transforming Process Safety Management: Challenges, Benefits, and Transition ...
Transforming Process Safety Management: Challenges, Benefits, and Transition ...
 
Lecture 2 .pdf
Lecture 2                           .pdfLecture 2                           .pdf
Lecture 2 .pdf
 
nvidia AI-gtc 2024 partial slide deck.pptx
nvidia AI-gtc 2024 partial slide deck.pptxnvidia AI-gtc 2024 partial slide deck.pptx
nvidia AI-gtc 2024 partial slide deck.pptx
 
Technology Features of Apollo HDD Machine, Its Technical Specification with C...
Technology Features of Apollo HDD Machine, Its Technical Specification with C...Technology Features of Apollo HDD Machine, Its Technical Specification with C...
Technology Features of Apollo HDD Machine, Its Technical Specification with C...
 
The relationship between iot and communication technology
The relationship between iot and communication technologyThe relationship between iot and communication technology
The relationship between iot and communication technology
 
Présentation IIRB 2024 Marine Cordonnier.pdf
Présentation IIRB 2024 Marine Cordonnier.pdfPrésentation IIRB 2024 Marine Cordonnier.pdf
Présentation IIRB 2024 Marine Cordonnier.pdf
 
Strategies of Urban Morphologyfor Improving Outdoor Thermal Comfort and Susta...
Strategies of Urban Morphologyfor Improving Outdoor Thermal Comfort and Susta...Strategies of Urban Morphologyfor Improving Outdoor Thermal Comfort and Susta...
Strategies of Urban Morphologyfor Improving Outdoor Thermal Comfort and Susta...
 
Litature Review: Research Paper work for Engineering
Litature Review: Research Paper work for EngineeringLitature Review: Research Paper work for Engineering
Litature Review: Research Paper work for Engineering
 
How to Write a Good Scientific Paper.pdf
How to Write a Good Scientific Paper.pdfHow to Write a Good Scientific Paper.pdf
How to Write a Good Scientific Paper.pdf
 

Conditional Statement in C Language

  • 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; ---------- ---------- --------- }