Happy Codings - Programming Code Examples
Html Css Web Design Sample Codes CPlusPlus Programming Sample Codes JavaScript Programming Sample Codes C Programming Sample Codes CSharp Programming Sample Codes Java Programming Sample Codes Php Programming Sample Codes Visual Basic Programming Sample Codes


C Programming Code Examples

Learn C Language

Break Statement in C Programming Language

Break Statement in C
The break is a keyword in C which is used to bring the program control out of the loop. The break statement is used inside loops or switch statement. The break statement breaks the loop one by one, i.e., in the case of nested loops, it breaks the inner loop first and then proceeds to outer loops.
Syntax for Break Statement in C
//loop statement... break;
When a break statement is encountered inside a loop, the loop is immediately terminated and the program control resumes at the next statement following the loop. It can be used to terminate a case in the switch statement (covered in the next chapter). If you are using nested loops, the break statement will stop the execution of the innermost loop and start executing the next line of code after the block.
/* bring the program control out of the loop by break keyword */ // Program to calculate the sum of numbers (10 numbers max) // If the user enters a negative number, the loop terminates #include <stdio.h> int main() { int i; double number, sum = 0.0; for (i = 1; i <= 10; ++i) { printf("Enter n%d: ", i); scanf("%lf", &number); // if the user enters a negative number, break the loop if (number < 0.0) { break; } sum += number; // sum = sum + number; } printf("Sum = %.2lf", sum); return 0; }





Open the file and point it to the file pointer fpoint1. Initialize the variables line_count, n_o_c_l, n_o_n_b_l, n_o_b_l, n_e_c to zero. Using while loop read the next line character




C Language program to Amstrong Numbers. Armstrong Number is a number which equal to the sum of the cubes of its individual digits For example, 407 is an armstrong number as