SlideShare a Scribd company logo
1 of 21
Decision making
statements in C
1Presented by: Group-E (The Anonymous)
Rabin BK
Bikash Dhakal
Bimal Pradhan
Bikram Bhurtel
Gagan Puri
Introduction to decision making statements
Decision making statements in C
If statement
If….else statement
If….else if….else statement
Nested if statement
Switch statement
The conditional operator(? : )
GOTO statement
References
Queries
2
Introduction to decision making statement in C
Also known as control statements
Controls the flow of execution
Executes program until a specified condition is met
One of the most important parts in programming
3
Decision making statements in C
if statement
switch statement
Conditional operator statement
goto statement
4
If statement
The expression must evaluate to true or false.
The “statement” can be a group of statements in braces:
Syntax:
5
if(expression)
{
Statement 1;
Statement 2;
}
6
#include<stdio.h>
#include<conio.h>
main( )
{
int n ;
printf ( "Enter your age: " ) ;
scanf ("%d", &n ) ;
if ( n>=20 )
{
printf (“nYou are in your adulthood. ” ) ;
}
getch();
}
Enter any number: 25
You are in your adulthood.
If else statement
 An extension version of if statement.
 Generally in the form of if (test expression)
7
if (test expression)
{
true block statement(s)
}
else
{
false block statement(s)
}
Example
8
#include<stdio.h>
#include<conio.h>
main()
{
int age;
printf("n enter your age:");
scanf("%d",&age);
if(age>=18)
{
printf("eligible for citizenship");
}
else
{
printf("n NOT ELIGIBLE");
}
getch();
}
enter your age:13
NOT ELIGIBLE
enter your age:20
eligible for citizenship
If …else if…. else statement
 It is used to give series of decision
 Syntax:
9
if (condition)
{
//statement 1
}
else if (condition 2)
{
//statement 2
}
else
{
// statement when all condition are false
}
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float a,b,c,d,r1,r2;
printf("Enter coefficients a, b and c: ");
scanf("%f%f%f",&a,&b,&c);
d=b*b-4*a*c;
if(d==0)
{
r1=-b/(2*a);
printf("n Roots are equal and is %.3f",r1);
}
else if(d>0)
{
d=sqrt(d);
r1=(-b+d)/(2*a);
r2=(-b-d)/(2*a);
printf("nRoots are real and r1=%.3f, r2=%.3f",r1,r2);
}
else
{
d=sqrt(fabs(d));
printf("n Roots are imaginary");
printf("n r1=%.3f + i%.3f",-b/(2*a),d/(2*a));
printf("n r2=%.3f - i%.3f",-b/(2*a),d/(2*a));
}
getch();
10
//Program to find the roots of the quadratic equations ax^2+bx+c=0
Enter coefficients a, b, c: 1
2
1
Roots are equal and is -1.000
Nested if-else statement
New block of if-else statement defined
in existing if or else block statement.
Syntax:
11
if(condition)
{
if(condition)
{
statement
}
else
{
statement
}
}
else
{
statement
}
12
#include <stdio.h>
#include <conio.h>
void main( )
{
int a,b,c;
printf("Enter 3 numbers: n");
scanf("%d%d%d",&a,&b,&c);
if(a>b)
{
if( a > c)
{
printf(“%d is greatest“,a);
}
else
{
printf(“%d is greatest“,c);
}
}
else
{
if( b> c)
{
printf(“%d is greatest“,b);
}
else
{
printf(“%d is greatest“,c);
}
}
getch();
}
Using Nested-if statement to check greatest
number among three input numbers
Enter 3 numbers:
9
11
5
11 is greatest
Enter 3 numbers:
49
55
88
88 is greatest
 Multi-way decision statement
 Tests the value of a given variable against a list of case values
 when a match is found, a block of statements associated with that
case is executed.
13
switch (var)
{
case case value 1:
statements;
break;
case case value 2:
statements;
break;
…….
…….
case case value n:
default:
statements;
break;
}
Should be an integer or characters
Known as case labels and should be constants or
constant expressions
And should be end with semicolon
14
#include<stdio.h>
int main()
{
char operator;
float firstNumber,secondNumber;
printf("Enter an operator (+, -): ");
scanf("%c", &operator);
printf("Enter two operands: ");
scanf("%f %f",&firstNumber, &secondNumber);
switch(operator)
{
case '+':
printf("%f + %f = %f",firstNumber, secondNumber, firstNumber +
secondNumber);
break;
case '-':
printf("%f - %f = %f",firstNumber, secondNumber, firstNumber -
secondNumber);
break;
default:
printf("Error! operator is not correct");
}
return 0;
}
Enter an operator(+,-): -
Enter two operands: 6
4
6.000000 – 4.000000 = 2.000000
Enter an operator(+,-): /
Enter two operands: 9
3
Error! operator is not correct
15
The ?: operator
Known as conditional operator
Used for making two-way decisions
Syntax:
16
Conditional expression ? exp1: exp2
Example:
17
//If True first exp is executed
//If False second exp is executed
#include <stdio.h>
#include <conio.h>
#include <math.h>
void main()
{
int a;
printf("Enter a number: ");
scanf("%d",&a);
(a%2==0?printf("Even"):printf("Odd"));
getch();
}
Enter a number: 9
Odd
Enter a number: 8
Even
The GOTO statement
Rarely used statement
Provides an unconditional jump from ‘goto’ to a labelled statement
in the same function
Syntax:
Requires label to identify the place where the branch is to be made
18
goto label;
-------------
-------------
label;
statement;
label;
statement;
-------------
-------------
goto label;
Forward jump Backward jump
Example:
19
#include <stdio.h>
#include <conio.h>
#include <math.h>
void main()
{
float y,x;
read:
printf("nEnter a number: ");
scanf("%f",&y);
if(y<0) goto read;
x=sqrt(y);
printf("nSquare root of %f---->%fn",y,x);
goto read;
}
Enter a number: 9
Square root of 9.000000---->3.000000
Enter a number: 25
Square root of 25.000000---->5.000000
References:
Websites:
google.com
codecadamy.com
tutorialspoint.com
External sources:
Text book: Programming in ANSIC (E-Balagurusamy)
20
Queries
21

More Related Content

What's hot

C programming project by navin thapa
C programming project by navin thapaC programming project by navin thapa
C programming project by navin thapa
Navinthp
 
Slide-show on Biometrics
Slide-show on BiometricsSlide-show on Biometrics
Slide-show on Biometrics
Pathik504
 
Graphical password authentication
Graphical password authenticationGraphical password authentication
Graphical password authentication
Asim Kumar Pathak
 

What's hot (20)

C programming project by navin thapa
C programming project by navin thapaC programming project by navin thapa
C programming project by navin thapa
 
C++ Overview PPT
C++ Overview PPTC++ Overview PPT
C++ Overview PPT
 
Security
SecuritySecurity
Security
 
C++ programming (Array)
C++ programming (Array)C++ programming (Array)
C++ programming (Array)
 
Python basic syntax
Python basic syntaxPython basic syntax
Python basic syntax
 
Slide-show on Biometrics
Slide-show on BiometricsSlide-show on Biometrics
Slide-show on Biometrics
 
Examinable Question and answer system programming
Examinable Question and answer system programmingExaminable Question and answer system programming
Examinable Question and answer system programming
 
User Experience Design in context of Graphic Design
User Experience Design in context of Graphic DesignUser Experience Design in context of Graphic Design
User Experience Design in context of Graphic Design
 
3D-Password: A More Secure Authentication
3D-Password: A More Secure Authentication3D-Password: A More Secure Authentication
3D-Password: A More Secure Authentication
 
Graphical password authentication
Graphical password authenticationGraphical password authentication
Graphical password authentication
 
Dynamic memory allocation in c
Dynamic memory allocation in cDynamic memory allocation in c
Dynamic memory allocation in c
 
Function in C program
Function in C programFunction in C program
Function in C program
 
C++ data types
C++ data typesC++ data types
C++ data types
 
C operators
C operatorsC operators
C operators
 
File handling in c
File handling in cFile handling in c
File handling in c
 
Data Types and Variables In C Programming
Data Types and Variables In C ProgrammingData Types and Variables In C Programming
Data Types and Variables In C Programming
 
String functions in C
String functions in CString functions in C
String functions in C
 
Characteristics of oop
Characteristics of oopCharacteristics of oop
Characteristics of oop
 
Multiple inheritance in c++
Multiple inheritance in c++Multiple inheritance in c++
Multiple inheritance in c++
 
Toy compiler
Toy compilerToy compiler
Toy compiler
 

Similar to Decision making statements in C

Branching statements
Branching statementsBranching statements
Branching statements
ArunMK17
 
CONTROLSTRUCTURES.ppt
CONTROLSTRUCTURES.pptCONTROLSTRUCTURES.ppt
CONTROLSTRUCTURES.ppt
Sanjjaayyy
 

Similar to Decision making statements in C (20)

Decision Making and Branching
Decision Making and BranchingDecision Making and Branching
Decision Making and Branching
 
Basics of Control Statement in C Languages
Basics of Control Statement in C LanguagesBasics of Control Statement in C Languages
Basics of Control Statement in C Languages
 
Control statements-Computer programming
Control statements-Computer programmingControl statements-Computer programming
Control statements-Computer programming
 
CH-4 (1).pptx
CH-4 (1).pptxCH-4 (1).pptx
CH-4 (1).pptx
 
Branching statements
Branching statementsBranching statements
Branching statements
 
Control Structures in C
Control Structures in CControl Structures in C
Control Structures in C
 
computer programming Control Statements.pptx
computer programming Control Statements.pptxcomputer programming Control Statements.pptx
computer programming Control Statements.pptx
 
Conditional statements
Conditional statementsConditional statements
Conditional statements
 
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
 
Control statement-Selective
Control statement-SelectiveControl statement-Selective
Control statement-Selective
 
Programming basics
Programming basicsProgramming basics
Programming basics
 
unit 2-Control Structures.pptx
unit 2-Control Structures.pptxunit 2-Control Structures.pptx
unit 2-Control Structures.pptx
 
Branching
BranchingBranching
Branching
 
CONTROLSTRUCTURES.ppt
CONTROLSTRUCTURES.pptCONTROLSTRUCTURES.ppt
CONTROLSTRUCTURES.ppt
 
Controls & Loops in C
Controls & Loops in C Controls & Loops in C
Controls & Loops in C
 
3. control statements
3. control statements3. control statements
3. control statements
 
C Programming Unit-2
C Programming Unit-2C Programming Unit-2
C Programming Unit-2
 
ICP - Lecture 7 and 8
ICP - Lecture 7 and 8ICP - Lecture 7 and 8
ICP - Lecture 7 and 8
 
C Control Statements.docx
C Control Statements.docxC Control Statements.docx
C Control Statements.docx
 
CONTROL FLOW in C.pptx
CONTROL FLOW in C.pptxCONTROL FLOW in C.pptx
CONTROL FLOW in C.pptx
 

More from Rabin BK

More from Rabin BK (20)

Artificial Intelligence in E-commerce
Artificial Intelligence in E-commerceArtificial Intelligence in E-commerce
Artificial Intelligence in E-commerce
 
Three address code generation
Three address code generationThree address code generation
Three address code generation
 
Consumer Oriented Application, Mercantile process and Mercantile models
Consumer Oriented Application, Mercantile process and Mercantile modelsConsumer Oriented Application, Mercantile process and Mercantile models
Consumer Oriented Application, Mercantile process and Mercantile models
 
Clang compiler `
Clang compiler `Clang compiler `
Clang compiler `
 
Simple Mail Transfer Protocol
Simple Mail Transfer ProtocolSimple Mail Transfer Protocol
Simple Mail Transfer Protocol
 
HTML text formatting tags
HTML text formatting tagsHTML text formatting tags
HTML text formatting tags
 
Data encryption in database management system
Data encryption in database management systemData encryption in database management system
Data encryption in database management system
 
Object Relational Database Management System(ORDBMS)
Object Relational Database Management System(ORDBMS)Object Relational Database Management System(ORDBMS)
Object Relational Database Management System(ORDBMS)
 
Kolmogorov Smirnov
Kolmogorov SmirnovKolmogorov Smirnov
Kolmogorov Smirnov
 
Job sequencing in Data Strcture
Job sequencing in Data StrctureJob sequencing in Data Strcture
Job sequencing in Data Strcture
 
Stack Data Structure
Stack Data StructureStack Data Structure
Stack Data Structure
 
Bluetooth
BluetoothBluetooth
Bluetooth
 
Data Science
Data ScienceData Science
Data Science
 
Graphics_3D viewing
Graphics_3D viewingGraphics_3D viewing
Graphics_3D viewing
 
Neural Netwrok
Neural NetwrokNeural Netwrok
Neural Netwrok
 
Watermarking in digital images
Watermarking in digital imagesWatermarking in digital images
Watermarking in digital images
 
Heun's Method
Heun's MethodHeun's Method
Heun's Method
 
Mutual Exclusion
Mutual ExclusionMutual Exclusion
Mutual Exclusion
 
Systems Usage
Systems UsageSystems Usage
Systems Usage
 
Manager of a company
Manager of a companyManager of a company
Manager of a company
 

Recently uploaded

Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
VictoriaMetrics
 

Recently uploaded (20)

WSO2Con2024 - Software Delivery in Hybrid Environments
WSO2Con2024 - Software Delivery in Hybrid EnvironmentsWSO2Con2024 - Software Delivery in Hybrid Environments
WSO2Con2024 - Software Delivery in Hybrid Environments
 
AzureNativeQumulo_HPC_Cloud_Native_Benchmarks.pdf
AzureNativeQumulo_HPC_Cloud_Native_Benchmarks.pdfAzureNativeQumulo_HPC_Cloud_Native_Benchmarks.pdf
AzureNativeQumulo_HPC_Cloud_Native_Benchmarks.pdf
 
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
 
WSO2CON 2024 - Lessons from the Field: Legacy Platforms – It's Time to Let Go...
WSO2CON 2024 - Lessons from the Field: Legacy Platforms – It's Time to Let Go...WSO2CON 2024 - Lessons from the Field: Legacy Platforms – It's Time to Let Go...
WSO2CON 2024 - Lessons from the Field: Legacy Platforms – It's Time to Let Go...
 
WSO2Con2024 - Unleashing the Financial Potential of 13 Million People
WSO2Con2024 - Unleashing the Financial Potential of 13 Million PeopleWSO2Con2024 - Unleashing the Financial Potential of 13 Million People
WSO2Con2024 - Unleashing the Financial Potential of 13 Million People
 
WSO2CON 2024 - Not Just Microservices: Rightsize Your Services!
WSO2CON 2024 - Not Just Microservices: Rightsize Your Services!WSO2CON 2024 - Not Just Microservices: Rightsize Your Services!
WSO2CON 2024 - Not Just Microservices: Rightsize Your Services!
 
WSO2CON 2024 Slides - Unlocking Value with AI
WSO2CON 2024 Slides - Unlocking Value with AIWSO2CON 2024 Slides - Unlocking Value with AI
WSO2CON 2024 Slides - Unlocking Value with AI
 
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...
 
WSO2CON2024 - Why Should You Consider Ballerina for Your Next Integration
WSO2CON2024 - Why Should You Consider Ballerina for Your Next IntegrationWSO2CON2024 - Why Should You Consider Ballerina for Your Next Integration
WSO2CON2024 - Why Should You Consider Ballerina for Your Next Integration
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
WSO2CON 2024 - Unlocking the Identity: Embracing CIAM 2.0 for a Competitive A...
WSO2CON 2024 - Unlocking the Identity: Embracing CIAM 2.0 for a Competitive A...WSO2CON 2024 - Unlocking the Identity: Embracing CIAM 2.0 for a Competitive A...
WSO2CON 2024 - Unlocking the Identity: Embracing CIAM 2.0 for a Competitive A...
 
Driving Innovation: Scania's API Revolution with WSO2
Driving Innovation: Scania's API Revolution with WSO2Driving Innovation: Scania's API Revolution with WSO2
Driving Innovation: Scania's API Revolution with WSO2
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
WSO2Con2024 - Hello Choreo Presentation - Kanchana
WSO2Con2024 - Hello Choreo Presentation - KanchanaWSO2Con2024 - Hello Choreo Presentation - Kanchana
WSO2Con2024 - Hello Choreo Presentation - Kanchana
 

Decision making statements in C

  • 1. Decision making statements in C 1Presented by: Group-E (The Anonymous) Rabin BK Bikash Dhakal Bimal Pradhan Bikram Bhurtel Gagan Puri
  • 2. Introduction to decision making statements Decision making statements in C If statement If….else statement If….else if….else statement Nested if statement Switch statement The conditional operator(? : ) GOTO statement References Queries 2
  • 3. Introduction to decision making statement in C Also known as control statements Controls the flow of execution Executes program until a specified condition is met One of the most important parts in programming 3
  • 4. Decision making statements in C if statement switch statement Conditional operator statement goto statement 4
  • 5. If statement The expression must evaluate to true or false. The “statement” can be a group of statements in braces: Syntax: 5 if(expression) { Statement 1; Statement 2; }
  • 6. 6 #include<stdio.h> #include<conio.h> main( ) { int n ; printf ( "Enter your age: " ) ; scanf ("%d", &n ) ; if ( n>=20 ) { printf (“nYou are in your adulthood. ” ) ; } getch(); } Enter any number: 25 You are in your adulthood.
  • 7. If else statement  An extension version of if statement.  Generally in the form of if (test expression) 7 if (test expression) { true block statement(s) } else { false block statement(s) }
  • 8. Example 8 #include<stdio.h> #include<conio.h> main() { int age; printf("n enter your age:"); scanf("%d",&age); if(age>=18) { printf("eligible for citizenship"); } else { printf("n NOT ELIGIBLE"); } getch(); } enter your age:13 NOT ELIGIBLE enter your age:20 eligible for citizenship
  • 9. If …else if…. else statement  It is used to give series of decision  Syntax: 9 if (condition) { //statement 1 } else if (condition 2) { //statement 2 } else { // statement when all condition are false }
  • 10. #include<stdio.h> #include<conio.h> #include<math.h> void main() { float a,b,c,d,r1,r2; printf("Enter coefficients a, b and c: "); scanf("%f%f%f",&a,&b,&c); d=b*b-4*a*c; if(d==0) { r1=-b/(2*a); printf("n Roots are equal and is %.3f",r1); } else if(d>0) { d=sqrt(d); r1=(-b+d)/(2*a); r2=(-b-d)/(2*a); printf("nRoots are real and r1=%.3f, r2=%.3f",r1,r2); } else { d=sqrt(fabs(d)); printf("n Roots are imaginary"); printf("n r1=%.3f + i%.3f",-b/(2*a),d/(2*a)); printf("n r2=%.3f - i%.3f",-b/(2*a),d/(2*a)); } getch(); 10 //Program to find the roots of the quadratic equations ax^2+bx+c=0 Enter coefficients a, b, c: 1 2 1 Roots are equal and is -1.000
  • 11. Nested if-else statement New block of if-else statement defined in existing if or else block statement. Syntax: 11 if(condition) { if(condition) { statement } else { statement } } else { statement }
  • 12. 12 #include <stdio.h> #include <conio.h> void main( ) { int a,b,c; printf("Enter 3 numbers: n"); scanf("%d%d%d",&a,&b,&c); if(a>b) { if( a > c) { printf(“%d is greatest“,a); } else { printf(“%d is greatest“,c); } } else { if( b> c) { printf(“%d is greatest“,b); } else { printf(“%d is greatest“,c); } } getch(); } Using Nested-if statement to check greatest number among three input numbers Enter 3 numbers: 9 11 5 11 is greatest Enter 3 numbers: 49 55 88 88 is greatest
  • 13.  Multi-way decision statement  Tests the value of a given variable against a list of case values  when a match is found, a block of statements associated with that case is executed. 13
  • 14. switch (var) { case case value 1: statements; break; case case value 2: statements; break; ……. ……. case case value n: default: statements; break; } Should be an integer or characters Known as case labels and should be constants or constant expressions And should be end with semicolon 14
  • 15. #include<stdio.h> int main() { char operator; float firstNumber,secondNumber; printf("Enter an operator (+, -): "); scanf("%c", &operator); printf("Enter two operands: "); scanf("%f %f",&firstNumber, &secondNumber); switch(operator) { case '+': printf("%f + %f = %f",firstNumber, secondNumber, firstNumber + secondNumber); break; case '-': printf("%f - %f = %f",firstNumber, secondNumber, firstNumber - secondNumber); break; default: printf("Error! operator is not correct"); } return 0; } Enter an operator(+,-): - Enter two operands: 6 4 6.000000 – 4.000000 = 2.000000 Enter an operator(+,-): / Enter two operands: 9 3 Error! operator is not correct 15
  • 16. The ?: operator Known as conditional operator Used for making two-way decisions Syntax: 16 Conditional expression ? exp1: exp2
  • 17. Example: 17 //If True first exp is executed //If False second exp is executed #include <stdio.h> #include <conio.h> #include <math.h> void main() { int a; printf("Enter a number: "); scanf("%d",&a); (a%2==0?printf("Even"):printf("Odd")); getch(); } Enter a number: 9 Odd Enter a number: 8 Even
  • 18. The GOTO statement Rarely used statement Provides an unconditional jump from ‘goto’ to a labelled statement in the same function Syntax: Requires label to identify the place where the branch is to be made 18 goto label; ------------- ------------- label; statement; label; statement; ------------- ------------- goto label; Forward jump Backward jump
  • 19. Example: 19 #include <stdio.h> #include <conio.h> #include <math.h> void main() { float y,x; read: printf("nEnter a number: "); scanf("%f",&y); if(y<0) goto read; x=sqrt(y); printf("nSquare root of %f---->%fn",y,x); goto read; } Enter a number: 9 Square root of 9.000000---->3.000000 Enter a number: 25 Square root of 25.000000---->5.000000