The BREAK statement is basically used to get out of the loop. When the break statement is encountered the control is automatically transferred to the statement executing just after the curly braces of the loop i.e. it allows us to get out of the existing loop at any instant of time.
/*Demonstration of break statement*/
main( )
{
int n, count ;
printf ( "Enter a number " ) ;
scanf ( "%d", &n ) ;
count = 2 ;
while ( count <= n - 1 )
{
if ( n % count == 0 )
{
printf ( "Not a prime number" ) ;
break ;
}
count++ ;
}
if ( count == n )
printf ( "Prime number" ) ;
}
/*Demonstration of break statement*/
main( )
{
int n, count ;
printf ( "Enter a number " ) ;
scanf ( "%d", &n ) ;
count = 2 ;
while ( count <= n - 1 )
{
if ( n % count == 0 )
{
printf ( "Not a prime number" ) ;
break ;
}
count++ ;
}
if ( count == n )
printf ( "Prime number" ) ;
}
Saturday
//
Labels:
C LANGUAGE
//
0
comments
//
0 comments to "BREAK STATEMENT IN C"
Powered by Blogger.
Blog Archive
-
▼
2011
(50)
-
▼
July
(38)
- INTRODUCTION TO C
- DATA SETS IN C
- DATA TYPES
- VARIABLES
- SIMPLE C PROGRAM
- PROGRAM USING SCANF() AND PRINTF()
- C INSTRUCTIONS
- INTRODUCTION TO DECISION CONTROL STRUCTURES
- IF STATEMENT
- IF STATEMENT PROGRAM
- IF ELSE STATEMENT
- NESTED IF ELSE
- DETERMINING ROOTS OF AN EQUATION
- ELSE IF STATEMENT
- LOGICAL AND ARITHMETIC OPERATORS
- CONDITIONAL OPERATORS
- LOOPS
- THE WHILE LOOP
- The for bend specify things about a bend in a ind...
- EXAMPLE OF FOR LOOP
- NESTING OF LOOPS
- THE ODD LOOP
- THE DO-WHILE LOOP
- BREAK STATEMENT IN C
- THE CONTINUE STATEMENT IN C
- SWITCH STATEMENT IN C
- SIMPLE PROGRAM SHOWING SWITCH STATEMENT
- THE GOTO STATEMENT IN C LANGUAGE
- FUNCTIONS IN C LANGUAGE
- CALLING FUNCTIONS IN C LANGUAGE
- CALL BY REFERENCE IN C LANGUAGE
- POINTERS IN C LANGUAGE
- SIMPLE PROGRAM SHOWING POINTER IN C LANGUAGE
- PROGRAM FOR FUNCTION CALL BY REFERENCE IN C
- SWAPPING OF TWO NUMBERS IN C
- RECURSION IN C LANGUAGE
- FACTORIAL OF A NUMBER WITHOUT RECURSION IN C
- ARRAYS IN C LANGUAGE
-
▼
July
(38)
Post a Comment